From 595647b18a571265f7e13e9f2064ccef9c865b22 Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Mon, 13 Mar 2023 16:32:36 +0800 Subject: [PATCH] refactor(nocodb): view update types --- .../nocodb/src/lib/services/views/formView.svc.ts | 11 +++++------ .../nocodb/src/lib/services/views/galleryView.svc.ts | 11 +++++++---- .../nocodb/src/lib/services/views/gridView.svc.ts | 6 +++--- .../nocodb/src/lib/services/views/kanbanView.svc.ts | 4 ++-- packages/nocodb/src/lib/services/views/mapView.svc.ts | 9 ++++----- 5 files changed, 21 insertions(+), 20 deletions(-) diff --git a/packages/nocodb/src/lib/services/views/formView.svc.ts b/packages/nocodb/src/lib/services/views/formView.svc.ts index e1dd9b3189..29b6b50e81 100644 --- a/packages/nocodb/src/lib/services/views/formView.svc.ts +++ b/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, ViewCreateReqType } from 'nocodb-sdk'; +import type { FormUpdateReqType, ViewCreateReqType } from 'nocodb-sdk'; export async function formViewGet(param: { formViewId: string }) { const formViewData = await FormView.getWithInfo(param.formViewId); @@ -27,13 +27,12 @@ export async function formViewCreate(param: { return view; } -// @ts-ignore export async function formViewUpdate(param: { 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' }); - return await FormView.update(param.formViewId, param.body); + T.emit('evt', { evt_type: 'view:updated', type: 'form' }); + return await FormView.update(param.formViewId, param.form); } diff --git a/packages/nocodb/src/lib/services/views/galleryView.svc.ts b/packages/nocodb/src/lib/services/views/galleryView.svc.ts index fafe3cb95f..f92884f895 100644 --- a/packages/nocodb/src/lib/services/views/galleryView.svc.ts +++ b/packages/nocodb/src/lib/services/views/galleryView.svc.ts @@ -2,7 +2,7 @@ import { ViewTypes } from 'nocodb-sdk'; import { T } from 'nc-help'; import { validatePayload } from '../../meta/api/helpers'; 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 }) { return await GalleryView.get(param.galleryViewId); @@ -10,7 +10,7 @@ export async function galleryViewGet(param: { galleryViewId: string }) { export async function galleryViewCreate(param: { tableId: string; - gallery: GalleryReqType; + gallery: ViewCreateReqType; }) { validatePayload('swagger.json#/components/schemas/GalleryReq', param.gallery); @@ -26,9 +26,12 @@ export async function galleryViewCreate(param: { export async function galleryViewUpdate(param: { 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' }); return await GalleryView.update(param.galleryViewId, param.gallery); diff --git a/packages/nocodb/src/lib/services/views/gridView.svc.ts b/packages/nocodb/src/lib/services/views/gridView.svc.ts index 950a3583e7..cee81819a0 100644 --- a/packages/nocodb/src/lib/services/views/gridView.svc.ts +++ b/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 { View } 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: { tableId: string; @@ -23,11 +23,11 @@ export async function gridViewCreate(param: { return view; } -// todo: json schema validation export async function gridViewUpdate(param: { viewId: string; - grid: GridReqType; + grid: GridUpdateReqType; }) { + validatePayload('swagger.json#/components/schemas/GridUpdateReq', param.grid); T.emit('evt', { evt_type: 'view:updated', type: 'grid' }); return await GridView.update(param.viewId, param.grid); } diff --git a/packages/nocodb/src/lib/services/views/kanbanView.svc.ts b/packages/nocodb/src/lib/services/views/kanbanView.svc.ts index dabb8e3d76..635cf4aaaa 100644 --- a/packages/nocodb/src/lib/services/views/kanbanView.svc.ts +++ b/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, ViewCreateReqType } from 'nocodb-sdk'; +import type { KanbanUpdateReqType, ViewCreateReqType } from 'nocodb-sdk'; export async function kanbanViewGet(param: { kanbanViewId: string }) { return await KanbanView.get(param.kanbanViewId); @@ -31,7 +31,7 @@ export async function kanbanViewCreate(param: { export async function kanbanViewUpdate(param: { kanbanViewId: string; - kanban: KanbanReqType; + kanban: KanbanUpdateReqType; }) { validatePayload( 'swagger.json#/components/schemas/KanbanUpdateReq', diff --git a/packages/nocodb/src/lib/services/views/mapView.svc.ts b/packages/nocodb/src/lib/services/views/mapView.svc.ts index c9a54ad8af..fcb3b80a04 100644 --- a/packages/nocodb/src/lib/services/views/mapView.svc.ts +++ b/packages/nocodb/src/lib/services/views/mapView.svc.ts @@ -3,7 +3,7 @@ import { T } from 'nc-help'; import View from '../../models/View'; import MapView from '../../models/MapView'; 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 }) { return await MapView.get(param.mapViewId); @@ -26,10 +26,9 @@ export async function mapViewCreate(param: { export async function mapViewUpdate(param: { mapViewId: string; - // todo: add MapReq in schema - map: MapType; + map: MapUpdateReqType; }) { + validatePayload('swagger.json#/components/schemas/MapUpdateReq', param.map); T.emit('evt', { evt_type: 'view:updated', type: 'map' }); - // todo: type correction - return await MapView.update(param.mapViewId, param.map as any); + return await MapView.update(param.mapViewId, param.map); }