Browse Source

refactor(nocodb): view update types

pull/5269/head
Wing-Kam Wong 2 years ago
parent
commit
595647b18a
  1. 11
      packages/nocodb/src/lib/services/views/formView.svc.ts
  2. 11
      packages/nocodb/src/lib/services/views/galleryView.svc.ts
  3. 6
      packages/nocodb/src/lib/services/views/gridView.svc.ts
  4. 4
      packages/nocodb/src/lib/services/views/kanbanView.svc.ts
  5. 9
      packages/nocodb/src/lib/services/views/mapView.svc.ts

11
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, ViewCreateReqType } from 'nocodb-sdk'; import type { FormUpdateReqType, 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);
@ -27,13 +27,12 @@ export async function formViewCreate(param: {
return view; return view;
} }
// @ts-ignore
export async function formViewUpdate(param: { export async function formViewUpdate(param: {
formViewId: string; formViewId: string;
body: FormReqType; form: FormUpdateReqType;
}) { }) {
validatePayload('swagger.json#/components/schemas/FormReq', param.body); validatePayload('swagger.json#/components/schemas/FormUpdateReq', param.form);
T.emit('evt', { evt_type: 'view:updated', type: 'grid' }); T.emit('evt', { evt_type: 'view:updated', type: 'form' });
return await FormView.update(param.formViewId, param.body); return await FormView.update(param.formViewId, param.form);
} }

11
packages/nocodb/src/lib/services/views/galleryView.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 { GalleryView, View } from '../../models'; import { GalleryView, View } from '../../models';
import type { GalleryReqType } from 'nocodb-sdk'; import type { ViewCreateReqType, GalleryUpdateReqType } from 'nocodb-sdk';
export async function galleryViewGet(param: { galleryViewId: string }) { export async function galleryViewGet(param: { galleryViewId: string }) {
return await GalleryView.get(param.galleryViewId); return await GalleryView.get(param.galleryViewId);
@ -10,7 +10,7 @@ export async function galleryViewGet(param: { galleryViewId: string }) {
export async function galleryViewCreate(param: { export async function galleryViewCreate(param: {
tableId: string; tableId: string;
gallery: GalleryReqType; gallery: ViewCreateReqType;
}) { }) {
validatePayload('swagger.json#/components/schemas/GalleryReq', param.gallery); validatePayload('swagger.json#/components/schemas/GalleryReq', param.gallery);
@ -26,9 +26,12 @@ export async function galleryViewCreate(param: {
export async function galleryViewUpdate(param: { export async function galleryViewUpdate(param: {
galleryViewId: string; galleryViewId: string;
gallery: GalleryReqType; gallery: GalleryUpdateReqType;
}) { }) {
validatePayload('swagger.json#/components/schemas/GalleryReq', param.gallery); validatePayload(
'swagger.json#/components/schemas/GalleryUpdateReq',
param.gallery
);
T.emit('evt', { evt_type: 'view:updated', type: 'gallery' }); T.emit('evt', { evt_type: 'view:updated', type: 'gallery' });
return await GalleryView.update(param.galleryViewId, param.gallery); return await GalleryView.update(param.galleryViewId, param.gallery);

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

@ -3,7 +3,7 @@ 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, ViewCreateReqType } from 'nocodb-sdk'; import type { GridUpdateReqType, ViewCreateReqType } from 'nocodb-sdk';
export async function gridViewCreate(param: { export async function gridViewCreate(param: {
tableId: string; tableId: string;
@ -23,11 +23,11 @@ export async function gridViewCreate(param: {
return view; return view;
} }
// todo: json schema validation
export async function gridViewUpdate(param: { export async function gridViewUpdate(param: {
viewId: string; viewId: string;
grid: GridReqType; grid: GridUpdateReqType;
}) { }) {
validatePayload('swagger.json#/components/schemas/GridUpdateReq', param.grid);
T.emit('evt', { evt_type: 'view:updated', type: 'grid' }); T.emit('evt', { evt_type: 'view:updated', type: 'grid' });
return await GridView.update(param.viewId, param.grid); return await GridView.update(param.viewId, param.grid);
} }

4
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, ViewCreateReqType } from 'nocodb-sdk'; import type { KanbanUpdateReqType, 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);
@ -31,7 +31,7 @@ export async function kanbanViewCreate(param: {
export async function kanbanViewUpdate(param: { export async function kanbanViewUpdate(param: {
kanbanViewId: string; kanbanViewId: string;
kanban: KanbanReqType; kanban: KanbanUpdateReqType;
}) { }) {
validatePayload( validatePayload(
'swagger.json#/components/schemas/KanbanUpdateReq', 'swagger.json#/components/schemas/KanbanUpdateReq',

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

@ -3,7 +3,7 @@ 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 { validatePayload } from '../../meta/api/helpers'; import { validatePayload } from '../../meta/api/helpers';
import type { MapType, ViewCreateReqType } from 'nocodb-sdk'; import type { MapUpdateReqType, 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);
@ -26,10 +26,9 @@ export async function mapViewCreate(param: {
export async function mapViewUpdate(param: { export async function mapViewUpdate(param: {
mapViewId: string; mapViewId: string;
// todo: add MapReq in schema map: MapUpdateReqType;
map: MapType;
}) { }) {
validatePayload('swagger.json#/components/schemas/MapUpdateReq', param.map);
T.emit('evt', { evt_type: 'view:updated', type: 'map' }); T.emit('evt', { evt_type: 'view:updated', type: 'map' });
// todo: type correction return await MapView.update(param.mapViewId, param.map);
return await MapView.update(param.mapViewId, param.map as any);
} }

Loading…
Cancel
Save