From 1637a48b4bda1af9ca08fc3c94b5802e3c01bd3c Mon Sep 17 00:00:00 2001 From: Pranav C Date: Sun, 9 Apr 2023 10:42:52 +0530 Subject: [PATCH] feat: grid view column apis Signed-off-by: Pranav C --- packages/nocodb-nest/src/app.module.ts | 3 +- .../grid-columns.controller.spec.ts | 20 +++++++++++ .../grid-columns/grid-columns.controller.ts | 33 +++++++++++++++++++ .../grid-columns/grid-columns.module.ts | 9 +++++ .../grid-columns/grid-columns.service.spec.ts | 18 ++++++++++ .../grid-columns/grid-columns.service.ts | 26 +++++++++++++++ 6 files changed, 108 insertions(+), 1 deletion(-) create mode 100644 packages/nocodb-nest/src/modules/grid-columns/grid-columns.controller.spec.ts create mode 100644 packages/nocodb-nest/src/modules/grid-columns/grid-columns.controller.ts create mode 100644 packages/nocodb-nest/src/modules/grid-columns/grid-columns.module.ts create mode 100644 packages/nocodb-nest/src/modules/grid-columns/grid-columns.service.spec.ts create mode 100644 packages/nocodb-nest/src/modules/grid-columns/grid-columns.service.ts diff --git a/packages/nocodb-nest/src/app.module.ts b/packages/nocodb-nest/src/app.module.ts index 7dc33ef67e..fea279457c 100644 --- a/packages/nocodb-nest/src/app.module.ts +++ b/packages/nocodb-nest/src/app.module.ts @@ -23,9 +23,10 @@ import { GridsModule } from './modules/grids/grids.module'; import { KanbansModule } from './modules/kanbans/kanbans.module'; import { GalleriesModule } from './modules/galleries/galleries.module'; import { FormColumnsModule } from './modules/form-columns/form-columns.module'; +import { GridColumnsModule } from './modules/grid-columns/grid-columns.module'; @Module({ - imports: [AuthModule, UsersModule, UtilsModule, ProjectsModule, TablesModule, ViewsModule, FiltersModule, SortsModule, ColumnsModule, ViewColumnsModule, BasesModule, HooksModule, SharedBasesModule, FormsModule, GridsModule, KanbansModule, GalleriesModule, FormColumnsModule], + imports: [AuthModule, UsersModule, UtilsModule, ProjectsModule, TablesModule, ViewsModule, FiltersModule, SortsModule, ColumnsModule, ViewColumnsModule, BasesModule, HooksModule, SharedBasesModule, FormsModule, GridsModule, KanbansModule, GalleriesModule, FormColumnsModule, GridColumnsModule], controllers: [], providers: [Connection, MetaService, JwtStrategy, ExtractProjectIdMiddleware], exports: [Connection, MetaService], diff --git a/packages/nocodb-nest/src/modules/grid-columns/grid-columns.controller.spec.ts b/packages/nocodb-nest/src/modules/grid-columns/grid-columns.controller.spec.ts new file mode 100644 index 0000000000..a3a12cce35 --- /dev/null +++ b/packages/nocodb-nest/src/modules/grid-columns/grid-columns.controller.spec.ts @@ -0,0 +1,20 @@ +import { Test, TestingModule } from '@nestjs/testing'; +import { GridColumnsController } from './grid-columns.controller'; +import { GridColumnsService } from './grid-columns.service'; + +describe('GridColumnsController', () => { + let controller: GridColumnsController; + + beforeEach(async () => { + const module: TestingModule = await Test.createTestingModule({ + controllers: [GridColumnsController], + providers: [GridColumnsService], + }).compile(); + + controller = module.get(GridColumnsController); + }); + + it('should be defined', () => { + expect(controller).toBeDefined(); + }); +}); diff --git a/packages/nocodb-nest/src/modules/grid-columns/grid-columns.controller.ts b/packages/nocodb-nest/src/modules/grid-columns/grid-columns.controller.ts new file mode 100644 index 0000000000..4ea25ff549 --- /dev/null +++ b/packages/nocodb-nest/src/modules/grid-columns/grid-columns.controller.ts @@ -0,0 +1,33 @@ +import { Body, Controller, Get, Param, Patch, UseGuards } from '@nestjs/common'; +import { GridColumnReqType } from 'nocodb-sdk'; +import { + Acl, + ExtractProjectIdMiddleware, +} from '../../middlewares/extract-project-id/extract-project-id.middleware'; +import { GridColumnsService } from './grid-columns.service'; +import { AuthGuard } from '@nestjs/passport'; + +@Controller('grid-columns') +@UseGuards(ExtractProjectIdMiddleware, AuthGuard('jwt')) +export class GridColumnsController { + constructor(private readonly gridColumnsService: GridColumnsService) {} + + @Get('/api/v1/db/meta/grids/:gridViewId/grid-columns') + @Acl('columnList') + async columnList(@Param('gridViewId') gridViewId: string) { + return await this.gridColumnsService.columnList({ + gridViewId, + }); + } + @Patch('/api/v1/db/meta/grid-columns/:gridViewColumnId') + @Acl('gridColumnUpdate') + async gridColumnUpdate( + @Param('gridViewColumnId') gridViewColumnId: string, + @Body() body: GridColumnReqType, + ) { + return this.gridColumnsService.gridColumnUpdate({ + gridViewColumnId, + grid: body, + }); + } +} diff --git a/packages/nocodb-nest/src/modules/grid-columns/grid-columns.module.ts b/packages/nocodb-nest/src/modules/grid-columns/grid-columns.module.ts new file mode 100644 index 0000000000..de6386e846 --- /dev/null +++ b/packages/nocodb-nest/src/modules/grid-columns/grid-columns.module.ts @@ -0,0 +1,9 @@ +import { Module } from '@nestjs/common'; +import { GridColumnsService } from './grid-columns.service'; +import { GridColumnsController } from './grid-columns.controller'; + +@Module({ + controllers: [GridColumnsController], + providers: [GridColumnsService] +}) +export class GridColumnsModule {} diff --git a/packages/nocodb-nest/src/modules/grid-columns/grid-columns.service.spec.ts b/packages/nocodb-nest/src/modules/grid-columns/grid-columns.service.spec.ts new file mode 100644 index 0000000000..953cd69927 --- /dev/null +++ b/packages/nocodb-nest/src/modules/grid-columns/grid-columns.service.spec.ts @@ -0,0 +1,18 @@ +import { Test, TestingModule } from '@nestjs/testing'; +import { GridColumnsService } from './grid-columns.service'; + +describe('GridColumnsService', () => { + let service: GridColumnsService; + + beforeEach(async () => { + const module: TestingModule = await Test.createTestingModule({ + providers: [GridColumnsService], + }).compile(); + + service = module.get(GridColumnsService); + }); + + it('should be defined', () => { + expect(service).toBeDefined(); + }); +}); diff --git a/packages/nocodb-nest/src/modules/grid-columns/grid-columns.service.ts b/packages/nocodb-nest/src/modules/grid-columns/grid-columns.service.ts new file mode 100644 index 0000000000..2c5f4caa07 --- /dev/null +++ b/packages/nocodb-nest/src/modules/grid-columns/grid-columns.service.ts @@ -0,0 +1,26 @@ +import { Injectable } from '@nestjs/common'; +import { GridColumnReqType } from 'nocodb-sdk'; +import { validatePayload } from '../../helpers'; +import { GridViewColumn } from '../../models'; +import { T } from 'nc-help'; + +@Injectable() +export class GridColumnsService { + + async columnList(param: { gridViewId: string }) { + return await GridViewColumn.list(param.gridViewId); + } + + async gridColumnUpdate(param: { + gridViewColumnId: string; + grid: GridColumnReqType; + }) { + validatePayload( + 'swagger.json#/components/schemas/GridColumnReq', + param.grid, + ); + + T.emit('evt', { evt_type: 'gridViewColumn:updated' }); + return await GridViewColumn.update(param.gridViewColumnId, param.grid); + } +}