Browse Source

refactor(nocodb): add validatePayload

pull/5222/head
Wing-Kam Wong 2 years ago
parent
commit
b29ef4505b
  1. 2
      packages/nocodb/src/lib/services/attachmentService.ts
  2. 8
      packages/nocodb/src/lib/services/viewColumnService.ts
  3. 11
      packages/nocodb/src/lib/services/viewService.ts

2
packages/nocodb/src/lib/services/attachmentService.ts

@ -11,6 +11,7 @@ export async function upload(param: {
// todo: proper type
files: unknown[];
}) {
// TODO: add getAjvValidatorMw
const filePath = sanitizeUrlPath(param.path?.toString()?.split('/') || ['']);
const destPath = path.join('nc', 'uploads', ...filePath);
@ -59,6 +60,7 @@ export async function uploadViaURL(param: {
size?: string | number;
}[];
}) {
// TODO: add getAjvValidatorMw
const filePath = sanitizeUrlPath(param?.path?.toString()?.split('/') || ['']);
const destPath = path.join('nc', 'uploads', ...filePath);

8
packages/nocodb/src/lib/services/viewColumnService.ts

@ -1,5 +1,7 @@
import { T } from 'nc-help';
import { validatePayload } from '../meta/api/helpers';
import { View } from '../models';
import type { ViewColumnReqType } from 'nocodb-sdk';
export async function columnList(param: { viewId: string }) {
return await View.getColumns(param.viewId);
@ -7,9 +9,11 @@ export async function columnList(param: { viewId: string }) {
export async function columnAdd(param: {
viewId: string;
columnId: string;
// todo: add proper type for grid column in swagger
column: any;
column: ViewColumnReqType;
}) {
validatePayload('swagger.json#/components/schemas/ViewColumnReq', param.column);
const viewColumn = await View.insertOrUpdateColumn(
param.viewId,
param.columnId,

11
packages/nocodb/src/lib/services/viewService.ts

@ -1,4 +1,5 @@
import { SharedViewType, ViewType } from 'nocodb-sdk';
import { SharedViewReqType, ViewReqType } from 'nocodb-sdk';
import { validatePayload } from '../meta/api/helpers';
import { Model, View } from '../models';
import { T } from 'nc-help';
import { xcVisibilityMetaGet } from './modelVisibilityService';
@ -33,8 +34,8 @@ export async function shareView(param: { viewId: string }) {
return await View.share(param.viewId);
}
// todo: type correctly
export async function viewUpdate(param: { viewId: string; view: ViewType }) {
export async function viewUpdate(param: { viewId: string; view: ViewReqType }) {
validatePayload('swagger.json#/components/schemas/ViewReq', param.view);
const result = await View.update(param.viewId, param.view);
T.emit('evt', { evt_type: 'vtable:updated', show_as: result.type });
return result;
@ -48,9 +49,9 @@ export async function viewDelete(param: { viewId: string }) {
export async function shareViewUpdate(param: {
viewId: string;
// todo: type correctly
sharedView: SharedViewType;
sharedView: SharedViewReqType;
}) {
validatePayload('swagger.json#/components/schemas/SharedViewReq', param.sharedView);
T.emit('evt', { evt_type: 'sharedView:updated' });
return await View.update(param.viewId, param.sharedView);
}

Loading…
Cancel
Save