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); + } +}