diff --git a/packages/nocodb/src/lib/controllers/gridViewColumnController.ts b/packages/nocodb/src/lib/controllers/gridViewColumnController.ts index f18a175c9e..3b535cce9e 100644 --- a/packages/nocodb/src/lib/controllers/gridViewColumnController.ts +++ b/packages/nocodb/src/lib/controllers/gridViewColumnController.ts @@ -1,17 +1,24 @@ import { Request, Response, Router } from 'express'; -import GridViewColumn from '../models/GridViewColumn'; -import { Tele } from 'nc-help'; import ncMetaAclMw from '../meta/helpers/ncMetaAclMw'; import { metaApiMetrics } from '../meta/helpers/apiMetrics'; import { getAjvValidatorMw } from '../meta/api/helpers'; +import { gridViewColumnService } from '../services'; export async function columnList(req: Request, res: Response) { - res.json(await GridViewColumn.list(req.params.gridViewId)); + res.json( + await gridViewColumnService.columnList({ + gridViewId: req.params.gridViewId, + }) + ); } export async function gridColumnUpdate(req: Request, res: Response) { - Tele.emit('evt', { evt_type: 'gridViewColumn:updated' }); - res.json(await GridViewColumn.update(req.params.gridViewColumnId, req.body)); + res.json( + await gridViewColumnService.gridColumnUpdate({ + gridViewColumnId: req.params.gridViewColumnId, + grid: req.body, + }) + ); } const router = Router({ mergeParams: true }); diff --git a/packages/nocodb/src/lib/controllers/viewColumnController.ts b/packages/nocodb/src/lib/controllers/viewColumnController.ts index a7c7fda7eb..aece1ca06e 100644 --- a/packages/nocodb/src/lib/controllers/viewColumnController.ts +++ b/packages/nocodb/src/lib/controllers/viewColumnController.ts @@ -1,33 +1,30 @@ import { Request, Response, Router } from 'express'; -import View from '../models/View'; -import { Tele } from 'nc-help'; import ncMetaAclMw from '../meta/helpers/ncMetaAclMw'; import { metaApiMetrics } from '../meta/helpers/apiMetrics'; +import { viewColumnService } from '../services'; export async function columnList(req: Request, res: Response) { - res.json(await View.getColumns(req.params.viewId)); + res.json(await viewColumnService.columnList({ viewId: req.params.viewId })); } + export async function columnAdd(req: Request, res: Response) { - const viewColumn = await View.insertOrUpdateColumn( - req.params.viewId, - req.body.fk_column_id, - { + const viewColumn = await viewColumnService.columnAdd({ + viewId: req.params.viewId, + columnId: req.body.fk_column_id, + column: { ...req.body, view_id: req.params.viewId, - } - ); - Tele.emit('evt', { evt_type: 'viewColumn:inserted' }); - + }, + }); res.json(viewColumn); } export async function columnUpdate(req: Request, res: Response) { - const result = await View.updateColumn( - req.params.viewId, - req.params.columnId, - req.body - ); - Tele.emit('evt', { evt_type: 'viewColumn:updated' }); + const result = await viewColumnService.columnUpdate({ + viewId: req.params.viewId, + columnId: req.params.columnId, + column: req.body, + }); res.json(result); } diff --git a/packages/nocodb/src/lib/services/galleryViewService.ts b/packages/nocodb/src/lib/services/galleryViewService.ts index c66d8d655e..9132202b74 100644 --- a/packages/nocodb/src/lib/services/galleryViewService.ts +++ b/packages/nocodb/src/lib/services/galleryViewService.ts @@ -1,8 +1,6 @@ -import { Request, Response, Router } from 'express'; -import { GalleryReqType, GalleryType, ViewTypes } from 'nocodb-sdk'; -import View from '../models/View'; -import GalleryView from '../models/GalleryView'; +import { GalleryReqType, ViewTypes } from 'nocodb-sdk'; import { Tele } from 'nc-help'; +import { GalleryView, View } from '../models' export async function galleryViewGet(param: { galleryViewId: string }) { return await GalleryView.get(param.galleryViewId); diff --git a/packages/nocodb/src/lib/services/gridViewColumnService.ts b/packages/nocodb/src/lib/services/gridViewColumnService.ts new file mode 100644 index 0000000000..06731ec3b1 --- /dev/null +++ b/packages/nocodb/src/lib/services/gridViewColumnService.ts @@ -0,0 +1,15 @@ +import { GridColumnReqType } from 'nocodb-sdk'; +import GridViewColumn from '../models/GridViewColumn'; +import { Tele } from 'nc-help'; + +export async function columnList(param: { gridViewId: string }) { + return await GridViewColumn.list(param.gridViewId); +} + +export async function gridColumnUpdate(param: { + gridViewColumnId: string; + grid: GridColumnReqType; +}) { + Tele.emit('evt', { evt_type: 'gridViewColumn:updated' }); + return await GridViewColumn.update(param.gridViewColumnId, param.grid); +} diff --git a/packages/nocodb/src/lib/services/index.ts b/packages/nocodb/src/lib/services/index.ts index 6d33b2a177..d4998f493b 100644 --- a/packages/nocodb/src/lib/services/index.ts +++ b/packages/nocodb/src/lib/services/index.ts @@ -14,3 +14,5 @@ export * as formViewColumnService from './formViewColumnService'; export * as gridViewService from './gridViewService'; export * as galleryViewService from './galleryViewService'; export * as kanbanViewService from './kanbanViewService'; +export * as gridViewColumnService from './gridViewColumnService'; +export * as viewColumnService from './viewColumnService'; diff --git a/packages/nocodb/src/lib/services/viewColumnService.ts b/packages/nocodb/src/lib/services/viewColumnService.ts new file mode 100644 index 0000000000..f6825691ad --- /dev/null +++ b/packages/nocodb/src/lib/services/viewColumnService.ts @@ -0,0 +1,39 @@ +import { Tele } from 'nc-help'; +import { View } from '../models' + +export async function columnList(param: { viewId: string }) { + return await View.getColumns(param.viewId); +} +export async function columnAdd(param: { + viewId: string; + columnId: string; + // todo: add proper type for grid column in swagger + column: any; +}) { + const viewColumn = await View.insertOrUpdateColumn( + param.viewId, + param.columnId, + { + ...param.column, + view_id: param.viewId, + } + ); + Tele.emit('evt', { evt_type: 'viewColumn:inserted' }); + + return viewColumn; +} + +export async function columnUpdate(param: { + viewId: string; + columnId: string; + // todo: add proper type for grid column in swagger + column: any; +}) { + const result = await View.updateColumn( + param.viewId, + param.columnId, + param.column + ); + Tele.emit('evt', { evt_type: 'viewColumn:updated' }); + return result; +}