From 5958fd989cee78fb5c9db9ab026b5d6e78d59036 Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Thu, 9 Mar 2023 17:54:19 +0800 Subject: [PATCH] refactor(nocodb): map kanbanView ctl to service --- .../lib/controllers/views/kanbanView.ctl.ts | 38 ++++++++++--------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/packages/nocodb/src/lib/controllers/views/kanbanView.ctl.ts b/packages/nocodb/src/lib/controllers/views/kanbanView.ctl.ts index fab14d3b1f..a77c5c8179 100644 --- a/packages/nocodb/src/lib/controllers/views/kanbanView.ctl.ts +++ b/packages/nocodb/src/lib/controllers/views/kanbanView.ctl.ts @@ -1,33 +1,34 @@ import { Router } from 'express'; -import { ViewTypes } from 'nocodb-sdk'; -import { T } from 'nc-help'; -import View from '../../models/View'; -import KanbanView from '../../models/KanbanView'; import ncMetaAclMw from '../../meta/helpers/ncMetaAclMw'; import { metaApiMetrics } from '../../meta/helpers/apiMetrics'; +import { kanbanViewService } from '../../services'; import type { KanbanType } from 'nocodb-sdk'; import type { Request, Response } from 'express'; -// todo: map to service - export async function kanbanViewGet(req: Request, res: Response) { - res.json(await KanbanView.get(req.params.kanbanViewId)); + res.json( + await kanbanViewService.kanbanViewGet({ + kanbanViewId: req.params.kanbanViewId, + }) + ); } export async function kanbanViewCreate(req: Request, res) { - T.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); + res.json( + await kanbanViewService.kanbanViewCreate({ + tableId: req.params.tableId, + kanban: req.body, + }) + ); } export async function kanbanViewUpdate(req, res) { - T.emit('evt', { evt_type: 'view:updated', type: 'kanban' }); - res.json(await KanbanView.update(req.params.kanbanViewId, req.body)); + res.json( + await kanbanViewService.kanbanViewUpdate({ + kanbanViewId: req.params.kanbanViewId, + kanban: req.body, + }) + ); } const router = Router({ mergeParams: true }); @@ -37,14 +38,17 @@ router.post( 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;