mirror of https://github.com/nocodb/nocodb
Pranav C
2 years ago
6 changed files with 149 additions and 1 deletions
@ -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(); |
||||
}); |
||||
}); |
@ -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, |
||||
}), |
||||
); |
||||
} |
||||
} |
@ -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 {} |
@ -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(); |
||||
}); |
||||
}); |
@ -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…
Reference in new issue