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 { validatePayload } from '../../meta/api/helpers';
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 }) {
const formViewData = await FormView.getWithInfo(param.formViewId);
@ -11,17 +11,19 @@ export async function formViewGet(param: { formViewId: string }) {
export async function formViewCreate(param: {
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({
...param.body,
// todo: sanitize
fk_model_id: param.tableId,
type: ViewTypes.FORM,
});
T.emit('evt', { evt_type: 'vtable:created', show_as: 'form' });
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 { View } from '../../models';
import { GridView } from '../../models';
import type { GridReqType } from 'nocodb-sdk';
import type { GridReqType, ViewCreateReqType } from 'nocodb-sdk';
export async function gridViewCreate(param: {
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({
...param.grid,
@ -17,7 +17,9 @@ export async function gridViewCreate(param: {
fk_model_id: param.tableId,
type: ViewTypes.GRID,
});
T.emit('evt', { evt_type: 'vtable:created', show_as: 'grid' });
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 { validatePayload } from '../../meta/api/helpers';
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 }) {
return await KanbanView.get(param.kanbanViewId);
@ -10,11 +10,12 @@ export async function kanbanViewGet(param: { kanbanViewId: string }) {
export async function kanbanViewCreate(param: {
tableId: string;
kanban: KanbanReqType;
kanban: ViewCreateReqType;
}) {
validatePayload('swagger.json#/components/schemas/KanbanReq', param.kanban);
T.emit('evt', { evt_type: 'vtable:created', show_as: 'kanban' });
validatePayload(
'swagger.json#/components/schemas/ViewCreateReq',
param.kanban
);
const view = await View.insert({
...param.kanban,
@ -22,6 +23,9 @@ export async function kanbanViewCreate(param: {
fk_model_id: param.tableId,
type: ViewTypes.KANBAN,
});
T.emit('evt', { evt_type: 'vtable:created', show_as: 'kanban' });
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 View from '../../models/View';
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 }) {
return await MapView.get(param.mapViewId);
@ -10,16 +11,16 @@ export async function mapViewGet(param: { mapViewId: string }) {
export async function mapViewCreate(param: {
tableId: string;
// todo: add MapReq in schema
map: MapType;
map: ViewCreateReqType;
}) {
T.emit('evt', { evt_type: 'vtable:created', show_as: 'map' });
validatePayload('swagger.json#/components/schemas/ViewCreateReq', param.map);
const view = await View.insert({
...param.map,
// todo: sanitize
fk_model_id: param.tableId,
type: ViewTypes.MAP,
});
T.emit('evt', { evt_type: 'vtable:created', show_as: 'map' });
return view;
}

Loading…
Cancel
Save