Browse Source

refcator: handler to service-controller - grid column and view column (WIP)

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/5239/head
Pranav C 2 years ago
parent
commit
b0d8ee8eb1
  1. 17
      packages/nocodb/src/lib/controllers/gridViewColumnController.ts
  2. 31
      packages/nocodb/src/lib/controllers/viewColumnController.ts
  3. 6
      packages/nocodb/src/lib/services/galleryViewService.ts
  4. 15
      packages/nocodb/src/lib/services/gridViewColumnService.ts
  5. 2
      packages/nocodb/src/lib/services/index.ts
  6. 39
      packages/nocodb/src/lib/services/viewColumnService.ts

17
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 });

31
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);
}

6
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);

15
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);
}

2
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';

39
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;
}
Loading…
Cancel
Save