From 3c745fc6757ff73dde8ad51b3066e2c23911bde5 Mon Sep 17 00:00:00 2001 From: Pranav C Date: Sat, 16 Apr 2022 15:48:56 +0530 Subject: [PATCH] refactor: replace nestedDelete with nestedRemove Signed-off-by: Pranav C --- .../components/virtualCell/belongsToCell.vue | 2 +- .../components/virtualCell/hasManyCell.vue | 2 +- .../components/virtualCell/manyToManyCell.vue | 2 +- packages/nocodb-sdk/src/lib/Api.ts | 42 ++-- scripts/sdk/swagger.json | 208 ++++++++++++++++-- 5 files changed, 214 insertions(+), 42 deletions(-) diff --git a/packages/nc-gui/components/project/spreadsheet/components/virtualCell/belongsToCell.vue b/packages/nc-gui/components/project/spreadsheet/components/virtualCell/belongsToCell.vue index 39eb7a4ac9..1f4c7fcd74 100644 --- a/packages/nc-gui/components/project/spreadsheet/components/virtualCell/belongsToCell.vue +++ b/packages/nc-gui/components/project/spreadsheet/components/virtualCell/belongsToCell.vue @@ -281,7 +281,7 @@ export default { const id = this.meta.columns.filter(c => c.pk).map(c => this.row[c.title]).join('___') // todo: audit - await this.$api.dbTableRow.nestedDelete( + await this.$api.dbTableRow.nestedRemove( 'noco', this.projectName, this.meta.title, diff --git a/packages/nc-gui/components/project/spreadsheet/components/virtualCell/hasManyCell.vue b/packages/nc-gui/components/project/spreadsheet/components/virtualCell/hasManyCell.vue index d778016cb4..287ce0e566 100644 --- a/packages/nc-gui/components/project/spreadsheet/components/virtualCell/hasManyCell.vue +++ b/packages/nc-gui/components/project/spreadsheet/components/virtualCell/hasManyCell.vue @@ -342,7 +342,7 @@ export default { return } const id = this.childMeta.columns.filter(c => c.pk).map(c => child[c.title]).join('___') - await this.$api.dbTableRow.nestedDelete( + await this.$api.dbTableRow.nestedRemove( 'noco', this.projectName, this.meta.title, diff --git a/packages/nc-gui/components/project/spreadsheet/components/virtualCell/manyToManyCell.vue b/packages/nc-gui/components/project/spreadsheet/components/virtualCell/manyToManyCell.vue index 7a317b99e6..9ada97bc6a 100644 --- a/packages/nc-gui/components/project/spreadsheet/components/virtualCell/manyToManyCell.vue +++ b/packages/nc-gui/components/project/spreadsheet/components/virtualCell/manyToManyCell.vue @@ -318,7 +318,7 @@ export default { const cid = this.childMeta.columns.filter(c => c.pk).map(c => child[c.title]).join('___') const pid = this.meta.columns.filter(c => c.pk).map(c => this.row[c.title]).join('___') - await this.$api.dbTableRow.nestedDelete( + await this.$api.dbTableRow.nestedRemove( 'noco', this.projectName, this.meta.title, diff --git a/packages/nocodb-sdk/src/lib/Api.ts b/packages/nocodb-sdk/src/lib/Api.ts index f7f0d2df31..a36717bc63 100644 --- a/packages/nocodb-sdk/src/lib/Api.ts +++ b/packages/nocodb-sdk/src/lib/Api.ts @@ -620,6 +620,15 @@ export type ColumnReqType = } | { uidt?: string; formula_raw?: string; formula?: string; title?: string }; +export interface UserInfoType { + id?: string; + email?: string; + email_verified?: string; + firstname?: string; + lastname?: string; + roles?: any; +} + import axios, { AxiosInstance, AxiosRequestConfig, ResponseType } from 'axios'; export type QueryParamsType = Record; @@ -798,7 +807,7 @@ export class Api< * @summary Signup * @request POST:/api/v1/db/auth/user/signup * @response `200` `{ token?: string }` OK - * @response `400` `void` Bad Request + * @response `400` `{ msg?: string }` Bad Request * @response `401` `void` Unauthorized * @response `403` `void` Forbidden */ @@ -806,7 +815,7 @@ export class Api< data: { email?: string; password?: string }, params: RequestParams = {} ) => - this.request<{ token?: string }, void>({ + this.request<{ token?: string }, { msg?: string } | void>({ path: `/api/v1/db/auth/user/signup`, method: 'POST', body: data, @@ -822,12 +831,13 @@ export class Api< * @summary Signin * @request POST:/api/v1/db/auth/user/signin * @response `200` `{ token?: string }` OK + * @response `400` `{ msg?: string }` Bad Request */ signin: ( data: { email: string; password: string }, params: RequestParams = {} ) => - this.request<{ token?: string }, any>({ + this.request<{ token?: string }, { msg?: string }>({ path: `/api/v1/db/auth/user/signin`, method: 'POST', body: data, @@ -843,12 +853,13 @@ export class Api< * @name Me * @summary User Info * @request GET:/api/v1/db/auth/user/me - * @response `200` `UserType` OK + * @response `200` `UserInfoType` OK */ - me: (params: RequestParams = {}) => - this.request({ + me: (query?: { project_id?: string }, params: RequestParams = {}) => + this.request({ path: `/api/v1/db/auth/user/me`, method: 'GET', + query: query, format: 'json', ...params, }), @@ -861,9 +872,10 @@ export class Api< * @summary Password Forgot * @request POST:/api/v1/db/auth/password/forgot * @response `200` `void` OK + * @response `401` `void` Unauthorized */ passwordForgot: (data: { email?: string }, params: RequestParams = {}) => - this.request({ + this.request({ path: `/api/v1/db/auth/password/forgot`, method: 'POST', body: data, @@ -878,21 +890,19 @@ export class Api< * @name PasswordChange * @summary Password Change * @request POST:/api/v1/db/auth/password/change - * @response `200` `void` OK + * @response `200` `{ msg?: string }` OK + * @response `400` `{ msg?: string }` Bad request */ passwordChange: ( - data: { - currentPassword?: string; - newPassword?: string; - verifyPassword?: string; - }, + data: { currentPassword?: string; newPassword?: string }, params: RequestParams = {} ) => - this.request({ + this.request<{ msg?: string }, { msg?: string }>({ path: `/api/v1/db/auth/password/change`, method: 'POST', body: data, type: ContentType.Json, + format: 'json', ...params, }), @@ -2466,11 +2476,11 @@ export class Api< * No description * * @tags DB table row - * @name NestedDelete + * @name NestedRemove * @request DELETE:/api/v1/db/data/{orgs}/{projectName}/{tableName}/{rowId}/{relationType}/{columnName}/{refRowId} * @response `200` `any` OK */ - nestedDelete: ( + nestedRemove: ( orgs: string, projectName: string, tableName: string, diff --git a/scripts/sdk/swagger.json b/scripts/sdk/swagger.json index 1188a262ce..fb8532e655 100644 --- a/scripts/sdk/swagger.json +++ b/scripts/sdk/swagger.json @@ -26,12 +26,58 @@ "type": "string" } } + }, + "examples": { + "Successful registration response": { + "value": { + "token": "string" + } + } } } } }, "400": { - "description": "Bad Request" + "description": "Bad Request", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "msg": { + "type": "string" + } + } + }, + "examples": { + "Invalid email": { + "value": { + "msg": "Invalid email" + } + }, + "Invalid invite url": { + "value": { + "msg": "Invalid invite url" + } + }, + "Expired invite url": { + "value": { + "msg": "Expired invite url, Please contact super admin to get a new invite url" + } + }, + "User already exist": { + "value": { + "msg": "User already exist" + } + }, + "Invite only signup": { + "value": { + "msg": "Not allowed to signup, contact super admin" + } + } + } + } + } }, "401": { "description": "Unauthorized" @@ -68,6 +114,21 @@ } } } + }, + "400": { + "description": "Bad Request", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "msg": { + "type": "string" + } + } + } + } + } } }, "tags": [ @@ -90,6 +151,14 @@ "email", "password" ] + }, + "examples": { + "example-1": { + "value": { + "email": "user@nocodb.com", + "password": "Password" + } + } } } } @@ -109,7 +178,21 @@ "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/User" + "$ref": "#/components/schemas/UserInfo" + }, + "examples": { + "example-1": { + "value": { + "id": "string", + "email": "string", + "email_verified": "string", + "firstname": "string", + "lastname": "string", + "roles": { + "editor": true + } + } + } } } } @@ -118,7 +201,17 @@ "tags": [ "Auth" ], - "description": "Returns authenticated user info" + "description": "Returns authenticated user info", + "parameters": [ + { + "schema": { + "type": "string" + }, + "in": "query", + "name": "project_id", + "description": "Pass project id to get project specific roles along with user info" + } + ] } }, "/api/v1/db/auth/password/forgot": { @@ -128,6 +221,9 @@ "responses": { "200": { "description": "OK" + }, + "401": { + "description": "Unauthorized" } }, "description": "Emails user with a reset url.", @@ -146,7 +242,8 @@ } } } - } + }, + "description": "Pass registered user email id in request body" } }, "parameters": [] @@ -157,7 +254,53 @@ "operationId": "auth-password-change", "responses": { "200": { - "description": "OK" + "description": "OK", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "msg": { + "type": "string" + } + } + }, + "examples": { + "Success response": { + "value": { + "msg": "Password updated successfully" + } + } + } + } + } + }, + "400": { + "description": "Bad request", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "msg": { + "type": "string" + } + } + }, + "examples": { + "Missing params": { + "value": { + "msg": "Missing new/old password" + } + }, + "Wrong password": { + "value": { + "msg": "Current password is wrong" + } + } + } + } + } } }, "description": "Change password of authenticated user with a new one.", @@ -175,14 +318,20 @@ }, "newPassword": { "type": "string" - }, - "verifyPassword": { - "type": "string" + } + } + }, + "examples": { + "example-1": { + "value": { + "currentPassword": "string", + "newPassword": "string" } } } } - } + }, + "description": "Old password need to be passed along with new password for changing password." } }, "parameters": [] @@ -292,7 +441,6 @@ }, "parameters": [] }, - "/api/v1/db/meta/projects/{projectId}/users": { "get": { "summary": "Project Users", @@ -1522,8 +1670,7 @@ "get": { "summary": "", "operationId": "db-view-column-list", - "responses": { - }, + "responses": {}, "tags": [ "DB View Column" ] @@ -2281,7 +2428,6 @@ } } }, - "/api/v1/db/data/{orgs}/{projectName}/{tableName}": { "parameters": [ { @@ -3104,7 +3250,8 @@ "name": "relationType", "in": "path", "required": true - },{ + }, + { "schema": { "type": "string" }, @@ -3245,7 +3392,7 @@ }, "delete": { "summary": "", - "operationId": "db-table-row-nested-delete", + "operationId": "db-table-row-nested-remove", "responses": { "200": { "description": "OK", @@ -3350,7 +3497,6 @@ ] } }, - "/api/v1/db/public/shared-view/{sharedViewUuid}/rows": { "parameters": [ { @@ -3421,7 +3567,7 @@ "multipart/form-data": { "schema": { "type": "object", - "properties": { } + "properties": {} } } } @@ -3707,7 +3853,6 @@ ] } }, - "/api/v1/db/meta/audits/comments": { "parameters": [], "get": { @@ -3945,7 +4090,6 @@ } } }, - "/api/v1/db/meta/tables/{tableId}/hooks": { "parameters": [ { @@ -4195,7 +4339,6 @@ ] } }, - "/api/v1/db/meta/plugins": { "parameters": [], "get": { @@ -4374,7 +4517,6 @@ ] } }, - "/api/v1/db/meta/connection/test": { "parameters": [], "post": { @@ -4480,7 +4622,6 @@ }, "parameters": [] }, - "/api/v1/db/meta/projects/{projectId}/api-tokens": { "get": { "summary": "Your GET endpoint", @@ -4583,7 +4724,6 @@ } ] }, - "/api/v1/db/storage/upload": { "post": { "summary": "Attachment", @@ -7031,6 +7171,28 @@ ], "description": "", "type": "object" + }, + "UserInfo": { + "title": "UserInfo", + "type": "object", + "properties": { + "id": { + "type": "string" + }, + "email": { + "type": "string" + }, + "email_verified": { + "type": "string" + }, + "firstname": { + "type": "string" + }, + "lastname": { + "type": "string" + }, + "roles": {} + } } }, "requestBodies": {