From fbfb849d0cebd9bad24623c3e6d88038574c1577 Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Wed, 18 May 2022 16:52:00 +0800 Subject: [PATCH] feat: add dataExist to dataAliasApis --- .../noco/meta/api/dataApis/dataAliasApis.ts | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/packages/nocodb/src/lib/noco/meta/api/dataApis/dataAliasApis.ts b/packages/nocodb/src/lib/noco/meta/api/dataApis/dataAliasApis.ts index 5eca0ca46c..1e01b0fe08 100644 --- a/packages/nocodb/src/lib/noco/meta/api/dataApis/dataAliasApis.ts +++ b/packages/nocodb/src/lib/noco/meta/api/dataApis/dataAliasApis.ts @@ -159,6 +159,31 @@ async function dataRead(req: Request, res: Response) { ); } +async function dataExist(req: Request, res: Response) { + const { model, view } = await getViewAndModelFromRequestByAliasOrId(req); + res.json(await getExist(model, view, req)); +} + +async function getExist(model, view: View, req) { + const base = await Base.get(model.base_id); + + const baseModel = await Model.getBaseModelSQL({ + id: model.id, + viewId: view?.id, + dbDriver: NcConnectionMgrv2.get(base) + }); + + const args: any = { ...req.query }; + try { + args.filterArr = JSON.parse(args.filterArrJson); + } catch (e) {} + try { + args.sortArr = JSON.parse(args.sortArrJson); + } catch (e) {} + + return await baseModel.exist(args); +} + const router = Router({ mergeParams: true }); // table data crud apis @@ -174,11 +199,18 @@ router.get( ncMetaAclMw(dataFindOne, 'dataFindOne') ); +router.get( + '/api/v1/db/data/:orgs/:projectName/:tableName/exist', + apiMetrics, + ncMetaAclMw(dataExist, 'dataExist') +); + router.get( '/api/v1/db/data/:orgs/:projectName/:tableName/count', apiMetrics, ncMetaAclMw(dataCount, 'dataCount') ); + router.get( '/api/v1/db/data/:orgs/:projectName/:tableName/views/:viewName/count', apiMetrics, @@ -190,11 +222,13 @@ router.get( apiMetrics, ncMetaAclMw(dataRead, 'dataRead') ); + router.patch( '/api/v1/db/data/:orgs/:projectName/:tableName/:rowId', apiMetrics, ncMetaAclMw(dataUpdate, 'dataUpdate') ); + router.delete( '/api/v1/db/data/:orgs/:projectName/:tableName/:rowId', apiMetrics, @@ -220,26 +254,36 @@ router.get( ncMetaAclMw(dataFindOne, 'dataFindOne') ); +router.get( + '/api/v1/db/data/:orgs/:projectName/:tableName/views/:viewName/exist', + apiMetrics, + ncMetaAclMw(dataExist, 'dataExist') +); + router.post( '/api/v1/db/data/:orgs/:projectName/:tableName', apiMetrics, ncMetaAclMw(dataInsert, 'dataInsert') ); + router.post( '/api/v1/db/data/:orgs/:projectName/:tableName/views/:viewName', apiMetrics, ncMetaAclMw(dataInsert, 'dataInsert') ); + router.patch( '/api/v1/db/data/:orgs/:projectName/:tableName/views/:viewName/:rowId', apiMetrics, ncMetaAclMw(dataUpdate, 'dataUpdate') ); + router.get( '/api/v1/db/data/:orgs/:projectName/:tableName/views/:viewName/:rowId', apiMetrics, ncMetaAclMw(dataRead, 'dataRead') ); + router.delete( '/api/v1/db/data/:orgs/:projectName/:tableName/views/:viewName/:rowId', apiMetrics,