Browse Source

feat: form view apis

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/5444/head
Pranav C 2 years ago
parent
commit
6fe95e9bde
  1. 3
      packages/nocodb-nest/src/app.module.ts
  2. 20
      packages/nocodb-nest/src/modules/forms/forms.controller.spec.ts
  3. 54
      packages/nocodb-nest/src/modules/forms/forms.controller.ts
  4. 9
      packages/nocodb-nest/src/modules/forms/forms.module.ts
  5. 18
      packages/nocodb-nest/src/modules/forms/forms.service.spec.ts
  6. 42
      packages/nocodb-nest/src/modules/forms/forms.service.ts

3
packages/nocodb-nest/src/app.module.ts

@ -18,9 +18,10 @@ import { ViewColumnsModule } from './modules/view-columns/view-columns.module';
import { BasesModule } from './modules/bases/bases.module'; import { BasesModule } from './modules/bases/bases.module';
import { HooksModule } from './modules/hooks/hooks.module'; import { HooksModule } from './modules/hooks/hooks.module';
import { SharedBasesModule } from './modules/shared-bases/shared-bases.module'; import { SharedBasesModule } from './modules/shared-bases/shared-bases.module';
import { FormsModule } from './modules/forms/forms.module';
@Module({ @Module({
imports: [AuthModule, UsersModule, UtilsModule, ProjectsModule, TablesModule, ViewsModule, FiltersModule, SortsModule, ColumnsModule, ViewColumnsModule, BasesModule, HooksModule, SharedBasesModule], imports: [AuthModule, UsersModule, UtilsModule, ProjectsModule, TablesModule, ViewsModule, FiltersModule, SortsModule, ColumnsModule, ViewColumnsModule, BasesModule, HooksModule, SharedBasesModule, FormsModule],
controllers: [], controllers: [],
providers: [Connection, MetaService, JwtStrategy, ExtractProjectIdMiddleware], providers: [Connection, MetaService, JwtStrategy, ExtractProjectIdMiddleware],
exports: [Connection, MetaService], exports: [Connection, MetaService],

20
packages/nocodb-nest/src/modules/forms/forms.controller.spec.ts

@ -0,0 +1,20 @@
import { Test, TestingModule } from '@nestjs/testing';
import { FormsController } from './forms.controller';
import { FormsService } from './forms.service';
describe('FormsController', () => {
let controller: FormsController;
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
controllers: [FormsController],
providers: [FormsService],
}).compile();
controller = module.get<FormsController>(FormsController);
});
it('should be defined', () => {
expect(controller).toBeDefined();
});
});

54
packages/nocodb-nest/src/modules/forms/forms.controller.ts

@ -0,0 +1,54 @@
import {
Body,
Controller,
Get,
Param,
Patch,
Post,
UseGuards,
} from '@nestjs/common';
import { ViewCreateReqType } from 'nocodb-sdk';
import {
Acl,
ExtractProjectIdMiddleware,
} from '../../middlewares/extract-project-id/extract-project-id.middleware';
import { FormsService } from './forms.service';
import { AuthGuard } from '@nestjs/passport';
@Controller('forms')
@UseGuards(ExtractProjectIdMiddleware, AuthGuard('jwt'))
export class FormsController {
constructor(private readonly formsService: FormsService) {}
@Get('/api/v1/db/meta/forms/:formViewId')
@Acl('formViewGet')
async formViewGet(@Param('formViewId') formViewId: string) {
const formViewData = await this.formsService.formViewGet({
formViewId,
});
return formViewData;
}
@Post('/api/v1/db/meta/tables/:tableId/forms')
@Acl('formViewCreate')
async formViewCreate(
@Param('tableId') tableId: string,
@Body() body: ViewCreateReqType,
) {
const view = await this.formsService.formViewCreate({
body,
tableId,
});
return view;
}
@Patch('/api/v1/db/meta/forms/:formViewId')
@Acl('formViewUpdate')
async formViewUpdate(req, res) {
res.json(
await this.formsService.formViewUpdate({
formViewId: req.params.formViewId,
form: req.body,
}),
);
}
}

9
packages/nocodb-nest/src/modules/forms/forms.module.ts

@ -0,0 +1,9 @@
import { Module } from '@nestjs/common';
import { FormsService } from './forms.service';
import { FormsController } from './forms.controller';
@Module({
controllers: [FormsController],
providers: [FormsService]
})
export class FormsModule {}

18
packages/nocodb-nest/src/modules/forms/forms.service.spec.ts

@ -0,0 +1,18 @@
import { Test, TestingModule } from '@nestjs/testing';
import { FormsService } from './forms.service';
describe('FormsService', () => {
let service: FormsService;
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [FormsService],
}).compile();
service = module.get<FormsService>(FormsService);
});
it('should be defined', () => {
expect(service).toBeDefined();
});
});

42
packages/nocodb-nest/src/modules/forms/forms.service.ts

@ -0,0 +1,42 @@
import { Injectable } from '@nestjs/common';
import { T } from 'nc-help';
import { FormUpdateReqType, ViewCreateReqType, ViewTypes } from 'nocodb-sdk';
import { validatePayload } from '../../helpers';
import { FormView, View } from '../../models';
@Injectable()
export class FormsService {
async formViewGet(param: { formViewId: string }) {
const formViewData = await FormView.getWithInfo(param.formViewId);
return formViewData;
}
async formViewCreate(param: { tableId: string; body: ViewCreateReqType }) {
validatePayload(
'swagger.json#/components/schemas/ViewCreateReq',
param.body,
);
const view = await View.insert({
...param.body,
// todo: sanitize
fk_model_id: param.tableId,
type: ViewTypes.FORM,
});
T.emit('evt', { evt_type: 'vtable:created', show_as: 'form' });
return view;
}
async formViewUpdate(param: { formViewId: string; form: FormUpdateReqType }) {
validatePayload(
'swagger.json#/components/schemas/FormUpdateReq',
param.form,
);
T.emit('evt', { evt_type: 'view:updated', type: 'form' });
return await FormView.update(param.formViewId, param.form);
}
}
Loading…
Cancel
Save