Browse Source

feat: kanban view apis

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

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

@ -19,9 +19,12 @@ import { BasesModule } from './modules/bases/bases.module';
import { HooksModule } from './modules/hooks/hooks.module';
import { SharedBasesModule } from './modules/shared-bases/shared-bases.module';
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';
@Module({
imports: [AuthModule, UsersModule, UtilsModule, ProjectsModule, TablesModule, ViewsModule, FiltersModule, SortsModule, ColumnsModule, ViewColumnsModule, BasesModule, HooksModule, SharedBasesModule, FormsModule],
imports: [AuthModule, UsersModule, UtilsModule, ProjectsModule, TablesModule, ViewsModule, FiltersModule, SortsModule, ColumnsModule, ViewColumnsModule, BasesModule, HooksModule, SharedBasesModule, FormsModule, GridsModule, KanbansModule, GalleriesModule],
controllers: [],
providers: [Connection, MetaService, JwtStrategy, ExtractProjectIdMiddleware],
exports: [Connection, MetaService],

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

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

53
packages/nocodb-nest/src/modules/kanbans/kanbans.controller.ts

@ -0,0 +1,53 @@
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 { KanbansService } from './kanbans.service';
import { AuthGuard } from '@nestjs/passport';
@Controller('kanbans')
@UseGuards(ExtractProjectIdMiddleware, AuthGuard('jwt'))
export class KanbansController {
constructor(private readonly kanbansService: KanbansService) {}
@Get('/api/v1/db/meta/kanbans/:kanbanViewId')
@Acl('kanbanViewGet')
async kanbanViewGet(@Param('kanbanViewId') kanbanViewId: string) {
return await this.kanbansService.kanbanViewGet({
kanbanViewId,
});
}
@Post('/api/v1/db/meta/tables/:tableId/kanbans')
@Acl('kanbanViewCreate')
async kanbanViewCreate(
@Param('tableId') tableId: string,
@Body() body: ViewCreateReqType,
) {
return await this.kanbansService.kanbanViewCreate({
tableId,
kanban: body,
});
}
@Patch('/api/v1/db/meta/kanbans/:kanbanViewId')
@Acl('kanbanViewUpdate')
async kanbanViewUpdate(req, res) {
res.json(
await this.kanbansService.kanbanViewUpdate({
kanbanViewId: req.params.kanbanViewId,
kanban: req.body,
}),
);
}
}

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

@ -0,0 +1,9 @@
import { Module } from '@nestjs/common';
import { KanbansService } from './kanbans.service';
import { KanbansController } from './kanbans.controller';
@Module({
controllers: [KanbansController],
providers: [KanbansService]
})
export class KanbansModule {}

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

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

45
packages/nocodb-nest/src/modules/kanbans/kanbans.service.ts

@ -0,0 +1,45 @@
import { Injectable } from '@nestjs/common';
import { KanbanUpdateReqType, ViewCreateReqType, ViewTypes } from 'nocodb-sdk';
import { validatePayload } from '../../helpers';
import { KanbanView, View } from '../../models';
import { T } from 'nc-help';
@Injectable()
export class KanbansService {
async kanbanViewGet(param: { kanbanViewId: string }) {
return await KanbanView.get(param.kanbanViewId);
}
async kanbanViewCreate(param: {
tableId: string;
kanban: ViewCreateReqType;
}) {
validatePayload(
'swagger.json#/components/schemas/ViewCreateReq',
param.kanban,
);
const view = await View.insert({
...param.kanban,
// todo: sanitize
fk_model_id: param.tableId,
type: ViewTypes.KANBAN,
});
T.emit('evt', { evt_type: 'vtable:created', show_as: 'kanban' });
return view;
}
async kanbanViewUpdate(param: {
kanbanViewId: string;
kanban: KanbanUpdateReqType;
}) {
validatePayload(
'swagger.json#/components/schemas/KanbanUpdateReq',
param.kanban,
),
T.emit('evt', { evt_type: 'view:updated', type: 'kanban' });
return await KanbanView.update(param.kanbanViewId, param.kanban);
}
}
Loading…
Cancel
Save