From 1529df00535ea839df758e602be70b5c8482ed5e Mon Sep 17 00:00:00 2001 From: Pranav C Date: Sat, 8 Apr 2023 00:05:16 +0530 Subject: [PATCH] feat: add all sort apis to controller Signed-off-by: Pranav C --- packages/nocodb-nest/src/app.module.ts | 3 +- .../src/modules/sorts/sorts.controller.ts | 122 +++++++++--------- 2 files changed, 63 insertions(+), 62 deletions(-) diff --git a/packages/nocodb-nest/src/app.module.ts b/packages/nocodb-nest/src/app.module.ts index a966425139..f4a4183bf0 100644 --- a/packages/nocodb-nest/src/app.module.ts +++ b/packages/nocodb-nest/src/app.module.ts @@ -13,9 +13,10 @@ import { TablesModule } from './modules/tables/tables.module'; import { ViewsModule } from './modules/views/views.module'; import { FiltersModule } from './modules/filters/filters.module'; import { SortsModule } from './modules/sorts/sorts.module'; +import { ColumnsModule } from './modules/columns/columns.module'; @Module({ - imports: [AuthModule, UsersModule, UtilsModule, ProjectsModule, TablesModule, ViewsModule, FiltersModule, SortsModule], + imports: [AuthModule, UsersModule, UtilsModule, ProjectsModule, TablesModule, ViewsModule, FiltersModule, SortsModule, ColumnsModule], controllers: [], providers: [Connection, MetaService, JwtStrategy, ExtractProjectIdMiddleware], exports: [Connection, MetaService], diff --git a/packages/nocodb-nest/src/modules/sorts/sorts.controller.ts b/packages/nocodb-nest/src/modules/sorts/sorts.controller.ts index 7e56b8af7a..a7fb95cab3 100644 --- a/packages/nocodb-nest/src/modules/sorts/sorts.controller.ts +++ b/packages/nocodb-nest/src/modules/sorts/sorts.controller.ts @@ -1,79 +1,79 @@ -import { Controller, Get, Param } from '@nestjs/common'; +import { + Body, + Controller, + Delete, + Get, + Param, + Patch, + Post, + UseGuards, +} from '@nestjs/common'; +import { AuthGuard } from '@nestjs/passport'; +import { SortReqType } from 'nocodb-sdk'; import { PagedResponseImpl } from '../../helpers/PagedResponse'; +import { + ExtractProjectIdMiddleware, + UseAclMiddleware, +} from '../../middlewares/extract-project-id/extract-project-id.middleware'; import { SortsService } from './sorts.service'; -@Controller('sorts') +@Controller() +@UseGuards(ExtractProjectIdMiddleware, AuthGuard('jwt')) export class SortsController { constructor(private readonly sortsService: SortsService) {} @Get('/api/v1/db/meta/views/:viewId/sorts/') + @UseAclMiddleware({ + permissionName: 'sortList', + }) async sortList(@Param('viewId') viewId: string) { - return; - new PagedResponseImpl( + return new PagedResponseImpl( await this.sortsService.sortList({ viewId, }), ); } -} - -/* + @Post('/api/v1/db/meta/views/:viewId/sorts/') + @UseAclMiddleware({ + permissionName: 'sortCreate', + }) + async sortCreate(@Param('viewId') viewId: string, @Body() body: SortReqType) { + const sort = await this.sortsService.sortCreate({ + sort: body, + viewId, + }); + return sort; + } -export async function sortCreate(req: Request, res) { - const sort = await sortService.sortCreate({ - sort: req.body, - viewId: req.params.viewId, - }); - res.json(sort); -} - -export async function sortUpdate(req, res) { - const sort = await sortService.sortUpdate({ - sortId: req.params.sortId, - sort: req.body, - }); - res.json(sort); -} + @Get('/api/v1/db/meta/sorts/:sortId') + @UseAclMiddleware({ + permissionName: 'sortGet', + }) + async sortGet(@Param('sortId') sortId: string) { + const sort = await this.sortsService.sortGet({ + sortId, + }); + return sort; + } -export async function sortDelete(req: Request, res: Response) { - const sort = await sortService.sortDelete({ - sortId: req.params.sortId, - }); - res.json(sort); -} + @Patch('/api/v1/db/meta/sorts/:sortId') + @UseAclMiddleware({ + permissionName: 'sortUpdate', + }) + async sortUpdate(@Param('sortId') sortId: string, @Body() body: SortReqType) { + const sort = await this.sortsService.sortUpdate({ + sortId, + sort: body, + }); + return sort; + } -export async function sortGet(req: Request, res: Response) { - const sort = await sortService.sortGet({ - sortId: req.params.sortId, - }); - res.json(sort); + @Delete('/api/v1/db/meta/sorts/:sortId') + async sortDelete(@Param('sortId') sortId: string) { + const sort = await this.sortsService.sortDelete({ + sortId, + }); + return sort; + } } - -const router = Router({ mergeParams: true }); - -router.post( - '/api/v1/db/meta/views/:viewId/sorts/', - metaApiMetrics, - ncMetaAclMw(sortCreate, 'sortCreate') -); - -router.get( - '/api/v1/db/meta/sorts/:sortId', - metaApiMetrics, - ncMetaAclMw(sortGet, 'sortGet') -); - -router.patch( - '/api/v1/db/meta/sorts/:sortId', - metaApiMetrics, - ncMetaAclMw(sortUpdate, 'sortUpdate') -); -router.delete( - '/api/v1/db/meta/sorts/:sortId', - metaApiMetrics, - ncMetaAclMw(sortDelete, 'sortDelete') -); -export default router; - -* */