Browse Source

refactor(nocodb): use ViewCreateReqType for view create functions

pull/5269/head
Wing-Kam Wong 2 years ago
parent
commit
05610d8f4a
  1. 10
      packages/nocodb/src/lib/services/views/formView.svc.ts
  2. 8
      packages/nocodb/src/lib/services/views/gridView.svc.ts
  3. 14
      packages/nocodb/src/lib/services/views/kanbanView.svc.ts
  4. 9
      packages/nocodb/src/lib/services/views/mapView.svc.ts

10
packages/nocodb/src/lib/services/views/formView.svc.ts

@ -2,7 +2,7 @@ import { T } from 'nc-help';
import { ViewTypes } from 'nocodb-sdk'; import { ViewTypes } from 'nocodb-sdk';
import { validatePayload } from '../../meta/api/helpers'; import { validatePayload } from '../../meta/api/helpers';
import { FormView, View } from '../../models'; import { FormView, View } from '../../models';
import type { FormReqType } from 'nocodb-sdk'; import type { FormReqType, ViewCreateReqType } from 'nocodb-sdk';
export async function formViewGet(param: { formViewId: string }) { export async function formViewGet(param: { formViewId: string }) {
const formViewData = await FormView.getWithInfo(param.formViewId); const formViewData = await FormView.getWithInfo(param.formViewId);
@ -11,17 +11,19 @@ export async function formViewGet(param: { formViewId: string }) {
export async function formViewCreate(param: { export async function formViewCreate(param: {
tableId: string; tableId: string;
body: FormReqType; body: ViewCreateReqType;
}) { }) {
validatePayload('swagger.json#/components/schemas/FormReq', param.body); validatePayload('swagger.json#/components/schemas/ViewCreateReq', param.body);
T.emit('evt', { evt_type: 'vtable:created', show_as: 'form' });
const view = await View.insert({ const view = await View.insert({
...param.body, ...param.body,
// todo: sanitize // todo: sanitize
fk_model_id: param.tableId, fk_model_id: param.tableId,
type: ViewTypes.FORM, type: ViewTypes.FORM,
}); });
T.emit('evt', { evt_type: 'vtable:created', show_as: 'form' });
return view; return view;
} }

8
packages/nocodb/src/lib/services/views/gridView.svc.ts

@ -3,13 +3,13 @@ import { ViewTypes } from 'nocodb-sdk';
import { validatePayload } from '../../meta/api/helpers'; import { validatePayload } from '../../meta/api/helpers';
import { View } from '../../models'; import { View } from '../../models';
import { GridView } from '../../models'; import { GridView } from '../../models';
import type { GridReqType } from 'nocodb-sdk'; import type { GridReqType, ViewCreateReqType } from 'nocodb-sdk';
export async function gridViewCreate(param: { export async function gridViewCreate(param: {
tableId: string; tableId: string;
grid: GridReqType; grid: ViewCreateReqType;
}) { }) {
validatePayload('swagger.json#/components/schemas/GridReq', param.grid); validatePayload('swagger.json#/components/schemas/ViewCreateReq', param.grid);
const view = await View.insert({ const view = await View.insert({
...param.grid, ...param.grid,
@ -17,7 +17,9 @@ export async function gridViewCreate(param: {
fk_model_id: param.tableId, fk_model_id: param.tableId,
type: ViewTypes.GRID, type: ViewTypes.GRID,
}); });
T.emit('evt', { evt_type: 'vtable:created', show_as: 'grid' }); T.emit('evt', { evt_type: 'vtable:created', show_as: 'grid' });
return view; return view;
} }

14
packages/nocodb/src/lib/services/views/kanbanView.svc.ts

@ -2,7 +2,7 @@ import { ViewTypes } from 'nocodb-sdk';
import { T } from 'nc-help'; import { T } from 'nc-help';
import { validatePayload } from '../../meta/api/helpers'; import { validatePayload } from '../../meta/api/helpers';
import { KanbanView, View } from '../../models'; import { KanbanView, View } from '../../models';
import type { KanbanReqType } from 'nocodb-sdk'; import type { KanbanReqType, ViewCreateReqType } from 'nocodb-sdk';
export async function kanbanViewGet(param: { kanbanViewId: string }) { export async function kanbanViewGet(param: { kanbanViewId: string }) {
return await KanbanView.get(param.kanbanViewId); return await KanbanView.get(param.kanbanViewId);
@ -10,11 +10,12 @@ export async function kanbanViewGet(param: { kanbanViewId: string }) {
export async function kanbanViewCreate(param: { export async function kanbanViewCreate(param: {
tableId: string; tableId: string;
kanban: KanbanReqType; kanban: ViewCreateReqType;
}) { }) {
validatePayload('swagger.json#/components/schemas/KanbanReq', param.kanban); validatePayload(
'swagger.json#/components/schemas/ViewCreateReq',
T.emit('evt', { evt_type: 'vtable:created', show_as: 'kanban' }); param.kanban
);
const view = await View.insert({ const view = await View.insert({
...param.kanban, ...param.kanban,
@ -22,6 +23,9 @@ export async function kanbanViewCreate(param: {
fk_model_id: param.tableId, fk_model_id: param.tableId,
type: ViewTypes.KANBAN, type: ViewTypes.KANBAN,
}); });
T.emit('evt', { evt_type: 'vtable:created', show_as: 'kanban' });
return view; return view;
} }

9
packages/nocodb/src/lib/services/views/mapView.svc.ts

@ -2,7 +2,8 @@ import { ViewTypes } from 'nocodb-sdk';
import { T } from 'nc-help'; import { T } from 'nc-help';
import View from '../../models/View'; import View from '../../models/View';
import MapView from '../../models/MapView'; import MapView from '../../models/MapView';
import type { MapType } from 'nocodb-sdk'; import { validatePayload } from '../../meta/api/helpers';
import type { MapType, ViewCreateReqType } from 'nocodb-sdk';
export async function mapViewGet(param: { mapViewId: string }) { export async function mapViewGet(param: { mapViewId: string }) {
return await MapView.get(param.mapViewId); return await MapView.get(param.mapViewId);
@ -10,16 +11,16 @@ export async function mapViewGet(param: { mapViewId: string }) {
export async function mapViewCreate(param: { export async function mapViewCreate(param: {
tableId: string; tableId: string;
// todo: add MapReq in schema map: ViewCreateReqType;
map: MapType;
}) { }) {
T.emit('evt', { evt_type: 'vtable:created', show_as: 'map' }); validatePayload('swagger.json#/components/schemas/ViewCreateReq', param.map);
const view = await View.insert({ const view = await View.insert({
...param.map, ...param.map,
// todo: sanitize // todo: sanitize
fk_model_id: param.tableId, fk_model_id: param.tableId,
type: ViewTypes.MAP, type: ViewTypes.MAP,
}); });
T.emit('evt', { evt_type: 'vtable:created', show_as: 'map' });
return view; return view;
} }

Loading…
Cancel
Save