diff --git a/packages/nocodb-nest/src/app.module.ts b/packages/nocodb-nest/src/app.module.ts index ba86887d08..7dc33ef67e 100644 --- a/packages/nocodb-nest/src/app.module.ts +++ b/packages/nocodb-nest/src/app.module.ts @@ -22,9 +22,10 @@ import { FormsModule } from './modules/forms/forms.module'; 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'; @Module({ - imports: [AuthModule, UsersModule, UtilsModule, ProjectsModule, TablesModule, ViewsModule, FiltersModule, SortsModule, ColumnsModule, ViewColumnsModule, BasesModule, HooksModule, SharedBasesModule, FormsModule, GridsModule, KanbansModule, GalleriesModule], + imports: [AuthModule, UsersModule, UtilsModule, ProjectsModule, TablesModule, ViewsModule, FiltersModule, SortsModule, ColumnsModule, ViewColumnsModule, BasesModule, HooksModule, SharedBasesModule, FormsModule, GridsModule, KanbansModule, GalleriesModule, FormColumnsModule], controllers: [], providers: [Connection, MetaService, JwtStrategy, ExtractProjectIdMiddleware], exports: [Connection, MetaService], diff --git a/packages/nocodb-nest/src/modules/form-columns/form-columns.controller.spec.ts b/packages/nocodb-nest/src/modules/form-columns/form-columns.controller.spec.ts new file mode 100644 index 0000000000..8bb2be4dc6 --- /dev/null +++ b/packages/nocodb-nest/src/modules/form-columns/form-columns.controller.spec.ts @@ -0,0 +1,20 @@ +import { Test, TestingModule } from '@nestjs/testing'; +import { FormColumnsController } from './form-columns.controller'; +import { FormColumnsService } from './form-columns.service'; + +describe('FormColumnsController', () => { + let controller: FormColumnsController; + + beforeEach(async () => { + const module: TestingModule = await Test.createTestingModule({ + controllers: [FormColumnsController], + providers: [FormColumnsService], + }).compile(); + + controller = module.get(FormColumnsController); + }); + + it('should be defined', () => { + expect(controller).toBeDefined(); + }); +}); diff --git a/packages/nocodb-nest/src/modules/form-columns/form-columns.controller.ts b/packages/nocodb-nest/src/modules/form-columns/form-columns.controller.ts new file mode 100644 index 0000000000..b3efdf6f73 --- /dev/null +++ b/packages/nocodb-nest/src/modules/form-columns/form-columns.controller.ts @@ -0,0 +1,27 @@ +import { Body, Controller, Param, Patch, UseGuards } from '@nestjs/common'; +import { + Acl, + ExtractProjectIdMiddleware, +} from '../../middlewares/extract-project-id/extract-project-id.middleware'; +import { FormColumnsService } from './form-columns.service'; +import { AuthGuard } from '@nestjs/passport'; + +class FormColumnUpdateReqType {} + +@Controller('form-columns') +@UseGuards(ExtractProjectIdMiddleware, AuthGuard('jwt')) +export class FormColumnsController { + constructor(private readonly formColumnsService: FormColumnsService) {} + + @Patch('/api/v1/db/meta/form-columns/:formViewColumnId') + @Acl('columnUpdate') + async columnUpdate( + @Param('formViewColumnId') formViewColumnId: string, + @Body() formViewColumnbody: FormColumnUpdateReqType, + ) { + return await this.formColumnsService.columnUpdate({ + formViewColumnId, + formViewColumn: formViewColumnbody, + }); + } +} diff --git a/packages/nocodb-nest/src/modules/form-columns/form-columns.module.ts b/packages/nocodb-nest/src/modules/form-columns/form-columns.module.ts new file mode 100644 index 0000000000..eba347a8d6 --- /dev/null +++ b/packages/nocodb-nest/src/modules/form-columns/form-columns.module.ts @@ -0,0 +1,9 @@ +import { Module } from '@nestjs/common'; +import { FormColumnsService } from './form-columns.service'; +import { FormColumnsController } from './form-columns.controller'; + +@Module({ + controllers: [FormColumnsController], + providers: [FormColumnsService] +}) +export class FormColumnsModule {} diff --git a/packages/nocodb-nest/src/modules/form-columns/form-columns.service.spec.ts b/packages/nocodb-nest/src/modules/form-columns/form-columns.service.spec.ts new file mode 100644 index 0000000000..13d6587592 --- /dev/null +++ b/packages/nocodb-nest/src/modules/form-columns/form-columns.service.spec.ts @@ -0,0 +1,18 @@ +import { Test, TestingModule } from '@nestjs/testing'; +import { FormColumnsService } from './form-columns.service'; + +describe('FormColumnsService', () => { + let service: FormColumnsService; + + beforeEach(async () => { + const module: TestingModule = await Test.createTestingModule({ + providers: [FormColumnsService], + }).compile(); + + service = module.get(FormColumnsService); + }); + + it('should be defined', () => { + expect(service).toBeDefined(); + }); +}); diff --git a/packages/nocodb-nest/src/modules/form-columns/form-columns.service.ts b/packages/nocodb-nest/src/modules/form-columns/form-columns.service.ts new file mode 100644 index 0000000000..5a3272e5a0 --- /dev/null +++ b/packages/nocodb-nest/src/modules/form-columns/form-columns.service.ts @@ -0,0 +1,25 @@ +import { Injectable } from '@nestjs/common'; +import { validatePayload } from '../../helpers' +import { FormViewColumn } from '../../models' +import { T } from 'nc-help' + + +@Injectable() +export class FormColumnsService { + async columnUpdate(param: { + formViewColumnId: string; + // todo: replace with FormColumnReq + formViewColumn: FormViewColumn; + }) { + validatePayload( + 'swagger.json#/components/schemas/FormColumnReq', + param.formViewColumn + ); + + T.emit('evt', { evt_type: 'formViewColumn:updated' }); + return await FormViewColumn.update( + param.formViewColumnId, + param.formViewColumn + ); + } +}