Browse Source

Merge pull request #2070 from nocodb/feat/exist-api

feat: exist api
pull/2074/head
աɨռɢӄաօռɢ 3 years ago committed by GitHub
parent
commit
6037e5b20a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      packages/noco-docs/content/en/developer-resources/rest-apis.md
  2. 71
      packages/nocodb-sdk/src/lib/Api.ts
  3. 10
      packages/nocodb/src/lib/dataMapper/lib/sql/BaseModelSqlv2.ts
  4. 32
      packages/nocodb/src/lib/noco/meta/api/dataApis/dataAliasApis.ts
  5. 6
      packages/nocodb/src/lib/utils/projectAcl.ts
  6. 177
      scripts/sdk/swagger.json

2
packages/noco-docs/content/en/developer-resources/rest-apis.md

@ -54,6 +54,7 @@ Currently, the default value for {orgs} is <b>noco</b>. Users will be able to ch
| Data | Delete| dbTableRow | bulkDeleteAll | /api/v1/db/data/bulk/{orgs}/{projectName}/{tableName}/all |
| Data | Get | dbTableRow | list | /api/v1/db/data/{orgs}/{projectName}/{tableName} |
| Data | Get | dbTableRow | findOne | /api/v1/db/data/{orgs}/{projectName}/{tableName}/find-one |
| Data | Get | dbTableRow | exist | /api/v1/db/data/{orgs}/{projectName}/{tableName}/{rowId}/exist |
| Data | Post | dbTableRow | create | /api/v1/db/data/{orgs}/{projectName}/{tableName} |
| Data | Get | dbTableRow | read | /api/v1/db/data/{orgs}/{projectName}/{tableName}/{rowId} |
| Data | Patch | dbTableRow | update | /api/v1/db/data/{orgs}/{projectName}/{tableName}/{rowId} |
@ -61,6 +62,7 @@ Currently, the default value for {orgs} is <b>noco</b>. Users will be able to ch
| Data | Get | dbTableRow | count | /api/v1/db/data/{orgs}/{projectName}/{tableName}/count |
| Data | Get | dbViewRow | list | /api/v1/db/data/{orgs}/{projectName}/{tableName}/views/{viewName} |
| Data | Get | dbViewRow | findOne | /api/v1/db/data/{orgs}/{projectName}/{tableName}/views/{viewName}/find-one |
| Data | Get | dbViewRow | exist | /api/v1/db/data/{orgs}/{projectName}/{tableName}/views/{viewName}/{rowId}/exist |
| Data | Post | dbViewRow | create | /api/v1/db/data/{orgs}/{projectName}/{tableName}/views/{viewName} |
| Data | Get | dbViewRow | read | /api/v1/db/data/{orgs}/{projectName}/{tableName}/views/{viewName}/{rowId} |
| Data | Patch | dbViewRow | update | /api/v1/db/data/{orgs}/{projectName}/{tableName}/views/{viewName}/{rowId} |

71
packages/nocodb-sdk/src/lib/Api.ts

@ -2258,30 +2258,6 @@ export class Api<
...params,
}),
/**
* No description
*
* @tags DB table row
* @name Count
* @summary table rows count
* @request GET:/api/v1/db/data/{orgs}/{projectName}/{tableName}/count
* @response `200` `any` OK
*/
count: (
orgs: string,
projectName: string,
tableName: string,
query?: { where?: string; nested?: any },
params: RequestParams = {}
) =>
this.request<any, any>({
path: `/api/v1/db/data/${orgs}/${projectName}/${tableName}/count`,
method: 'GET',
query: query,
format: 'json',
...params,
}),
/**
* No description
*
@ -2353,6 +2329,29 @@ export class Api<
...params,
}),
/**
* @description check row with provided primary key exists or not
*
* @tags DB table row
* @name Exist
* @summary Table row exist
* @request GET:/api/v1/db/data/{orgs}/{projectName}/{tableName}/{rowId}/exist
* @response `201` `any` Created
*/
exist: (
orgs: string,
projectName: string,
tableName: string,
rowId: string,
params: RequestParams = {}
) =>
this.request<any, any>({
path: `/api/v1/db/data/${orgs}/${projectName}/${tableName}/${rowId}/exist`,
method: 'GET',
format: 'json',
...params,
}),
/**
* No description
*
@ -2785,6 +2784,30 @@ export class Api<
...params,
}),
/**
* @description check row with provided primary key exists or not
*
* @tags DB view row
* @name Exist
* @summary Table view row exist
* @request GET:/api/v1/db/data/{orgs}/{projectName}/{tableName}/views/{viewName}/{rowId}/exist
* @response `201` `any` Created
*/
exist: (
orgs: string,
projectName: string,
tableName: string,
viewName: string,
rowId: string,
params: RequestParams = {}
) =>
this.request<any, any>({
path: `/api/v1/db/data/${orgs}/${projectName}/${tableName}/views/${viewName}/${rowId}/exist`,
method: 'GET',
format: 'json',
...params,
}),
/**
* @description CSV or Excel export
*

10
packages/nocodb/src/lib/dataMapper/lib/sql/BaseModelSqlv2.ts

@ -102,6 +102,16 @@ class BaseModelSqlv2 {
return data;
}
public async exist(id?: any): Promise<any> {
const qb = this.dbDriver(this.model.table_name);
await this.selectObject({ qb });
const pks = this.model.primaryKeys;
if ((id + '').split('___').length != pks.length) {
return false;
}
return !!(await qb.where(_wherePk(pks, id)).first());
}
public async findOne(
args: {
where?: string;

32
packages/nocodb/src/lib/noco/meta/api/dataApis/dataAliasApis.ts

@ -159,6 +159,19 @@ async function dataRead(req: Request, res: Response) {
);
}
async function dataExist(req: Request, res: Response) {
const { model, view } = await getViewAndModelFromRequestByAliasOrId(req);
const base = await Base.get(model.base_id);
const baseModel = await Model.getBaseModelSQL({
id: model.id,
viewId: view?.id,
dbDriver: NcConnectionMgrv2.get(base)
});
res.json(await baseModel.exist(req.params.rowId));
}
const router = Router({ mergeParams: true });
// table data crud apis
@ -174,11 +187,18 @@ router.get(
ncMetaAclMw(dataFindOne, 'dataFindOne')
);
router.get(
'/api/v1/db/data/:orgs/:projectName/:tableName/:rowId/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 +210,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 +242,36 @@ router.get(
ncMetaAclMw(dataFindOne, 'dataFindOne')
);
router.get(
'/api/v1/db/data/:orgs/:projectName/:tableName/views/:viewName/:rowId/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,

6
packages/nocodb/src/lib/utils/projectAcl.ts

@ -21,6 +21,8 @@ export default {
dataDelete: true,
dataInsert: true,
dataRead: true,
dataExist: true,
dataFindOne: true,
commentsCount: true,
exportCsv: true,
@ -153,6 +155,8 @@ export default {
// data
dataList: true,
dataRead: true,
dataExist: true,
dataFindOne: true,
commentsCount: true,
xcTableAndViewList: true,
@ -188,6 +192,8 @@ export default {
// data
dataList: true,
dataRead: true,
dataExist: true,
dataFindOne: true,
commentsCount: true,
exportCsv: true,

177
scripts/sdk/swagger.json

@ -2600,67 +2600,6 @@
}
}
},
"/api/v1/db/data/{orgs}/{projectName}/{tableName}/count": {
"parameters": [
{
"schema": {
"type": "string"
},
"name": "orgs",
"in": "path",
"required": true
},
{
"schema": {
"type": "string"
},
"name": "projectName",
"in": "path",
"required": true
},
{
"schema": {
"type": "string"
},
"name": "tableName",
"in": "path",
"required": true
}
],
"get": {
"summary": "table rows count",
"operationId": "db-table-row-count",
"description": "",
"tags": [
"DB table row"
],
"parameters": [
{
"schema": {
"type": "string"
},
"in": "query",
"name": "where"
},
{
"schema": {},
"in": "query",
"name": "nested",
"description": "Query params for nested data"
}
],
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {}
}
}
}
}
}
},
"/api/v1/db/data/{orgs}/{projectName}/{tableName}/views/{viewName}": {
"parameters": [
{
@ -3019,6 +2958,68 @@
"description": ""
}
},
"/api/v1/db/data/{orgs}/{projectName}/{tableName}/views/{viewName}/{rowId}/exist": {
"parameters": [
{
"schema": {
"type": "string"
},
"name": "orgs",
"in": "path",
"required": true
},
{
"schema": {
"type": "string"
},
"name": "projectName",
"in": "path",
"required": true
},
{
"schema": {
"type": "string"
},
"name": "tableName",
"in": "path",
"required": true
},
{
"schema": {
"type": "string"
},
"name": "viewName",
"in": "path",
"required": true
},
{
"schema": {
"type": "string"
},
"name": "rowId",
"in": "path",
"required": true
}
],
"get": {
"summary": "Table view row exist",
"operationId": "db-view-row-exist",
"responses": {
"201": {
"description": "Created",
"content": {
"application/json": {
"schema": {}
}
}
}
},
"description": "check row with provided primary key exists or not",
"tags": [
"DB view row"
]
}
},
"/api/v1/db/data/{orgs}/{projectName}/{tableName}/{rowId}": {
"parameters": [
{
@ -3110,6 +3111,60 @@
"description": ""
}
},
"/api/v1/db/data/{orgs}/{projectName}/{tableName}/{rowId}/exist": {
"parameters": [
{
"schema": {
"type": "string"
},
"name": "orgs",
"in": "path",
"required": true
},
{
"schema": {
"type": "string"
},
"name": "projectName",
"in": "path",
"required": true
},
{
"schema": {
"type": "string"
},
"name": "tableName",
"in": "path",
"required": true
},
{
"schema": {
"type": "string"
},
"name": "rowId",
"in": "path",
"required": true
}
],
"get": {
"summary": "Table row exist",
"operationId": "db-table-row-exist",
"responses": {
"201": {
"description": "Created",
"content": {
"application/json": {
"schema": {}
}
}
}
},
"description": "check row with provided primary key exists or not",
"tags": [
"DB table row"
]
}
},
"/api/v1/db/data/bulk/{orgs}/{projectName}/{tableName}": {
"parameters": [
{

Loading…
Cancel
Save