diff --git a/packages/nocodb/src/lib/meta/api/kanbanViewApis.ts b/packages/nocodb/src/lib/meta/api/kanbanViewApis.ts new file mode 100644 index 0000000000..6bf385fec5 --- /dev/null +++ b/packages/nocodb/src/lib/meta/api/kanbanViewApis.ts @@ -0,0 +1,46 @@ +import { Request, Response, Router } from 'express'; +import { KanbanType, ViewTypes } from 'nocodb-sdk'; +import View from '../../models/View'; +import KanbanView from '../../models/KanbanView'; +import ncMetaAclMw from '../helpers/ncMetaAclMw'; +import { Tele } from 'nc-help'; +import { metaApiMetrics } from '../helpers/apiMetrics'; + +export async function kanbanViewGet(req: Request, res: Response) { + res.json(await KanbanView.get(req.params.kanbanViewId)); +} + +export async function kanbanViewCreate(req: Request, res) { + Tele.emit('evt', { evt_type: 'vtable:created', show_as: 'kanban' }); + const view = await View.insert({ + ...req.body, + // todo: sanitize + fk_model_id: req.params.tableId, + type: ViewTypes.KANBAN, + }); + res.json(view); +} + +export async function kanbanViewUpdate(req, res) { + Tele.emit('evt', { evt_type: 'view:updated', type: 'kanban' }); + res.json(await KanbanView.update(req.params.kanbanViewId, req.body)); +} + +const router = Router({ mergeParams: true }); + +router.post( + '/api/v1/db/meta/tables/:tableId/kanbans', + metaApiMetrics, + ncMetaAclMw(kanbanViewCreate, 'kanbanViewCreate') +); +router.patch( + '/api/v1/db/meta/kanbans/:kanbanViewId', + metaApiMetrics, + ncMetaAclMw(kanbanViewUpdate, 'kanbanViewUpdate') +); +router.get( + '/api/v1/db/meta/kanbans/:kanbanViewId', + metaApiMetrics, + ncMetaAclMw(kanbanViewGet, 'kanbanViewGet') +); +export default router;