Browse Source

feat: set response code as 200

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/5444/head
Pranav C 2 years ago
parent
commit
c46b9b85ee
  1. 475
      packages/nocodb-nest/src/middlewares/catchError.ts
  2. 5
      packages/nocodb-nest/src/modules/api-tokens/api-tokens.controller.ts
  3. 6
      packages/nocodb-nest/src/modules/attachments/attachments.controller.ts
  4. 6
      packages/nocodb-nest/src/modules/audits/audits.controller.ts
  5. 6
      packages/nocodb-nest/src/modules/auth/auth.controller.ts
  6. 5
      packages/nocodb-nest/src/modules/bases/bases.controller.ts
  7. 6
      packages/nocodb-nest/src/modules/columns/columns.controller.ts
  8. 5
      packages/nocodb-nest/src/modules/datas/bulk-data-alias/bulk-data-alias.controller.ts
  9. 5
      packages/nocodb-nest/src/modules/datas/data-alias.controller.ts
  10. 6
      packages/nocodb-nest/src/modules/datas/datas.controller.ts
  11. 5
      packages/nocodb-nest/src/modules/datas/old-datas/old-datas.controller.ts
  12. 6
      packages/nocodb-nest/src/modules/filters/filters.controller.ts
  13. 5
      packages/nocodb-nest/src/modules/forms/forms.controller.ts
  14. 5
      packages/nocodb-nest/src/modules/galleries/galleries.controller.ts
  15. 5
      packages/nocodb-nest/src/modules/grids/grids.controller.ts
  16. 6
      packages/nocodb-nest/src/modules/hooks/hooks.controller.ts
  17. 5
      packages/nocodb-nest/src/modules/import/import.controller.ts
  18. 5
      packages/nocodb-nest/src/modules/kanbans/kanbans.controller.ts
  19. 5
      packages/nocodb-nest/src/modules/maps/maps.controller.ts
  20. 4
      packages/nocodb-nest/src/modules/meta-diffs/meta-diffs.controller.ts
  21. 5
      packages/nocodb-nest/src/modules/model-visibilities/model-visibilities.controller.ts
  22. 3
      packages/nocodb-nest/src/modules/org-lcense/org-lcense.controller.ts
  23. 5
      packages/nocodb-nest/src/modules/org-tokens/org-tokens.controller.ts
  24. 9
      packages/nocodb-nest/src/modules/org-users/org-users.controller.ts
  25. 3
      packages/nocodb-nest/src/modules/plugins/plugins.controller.ts
  26. 6
      packages/nocodb-nest/src/modules/project-users/project-users.controller.ts
  27. 5
      packages/nocodb-nest/src/modules/projects/projects.controller.ts
  28. 3
      packages/nocodb-nest/src/modules/public-datas/public-datas.controller.ts
  29. 5
      packages/nocodb-nest/src/modules/shared-bases/shared-bases.controller.ts
  30. 5
      packages/nocodb-nest/src/modules/sorts/sorts.controller.ts
  31. 5
      packages/nocodb-nest/src/modules/sync/sync.controller.ts
  32. 6
      packages/nocodb-nest/src/modules/tables/tables.controller.ts
  33. 3
      packages/nocodb-nest/src/modules/test/test.controller.ts
  34. 6
      packages/nocodb-nest/src/modules/users/users.controller.ts
  35. 7
      packages/nocodb-nest/src/modules/utils/utils.controller.ts
  36. 5
      packages/nocodb-nest/src/modules/view-columns/view-columns.controller.ts
  37. 7
      packages/nocodb-nest/src/modules/views/views.controller.ts

475
packages/nocodb-nest/src/middlewares/catchError.ts

@ -1,471 +1,4 @@
import type { ErrorObject } from 'ajv';
enum DBError {
TABLE_EXIST = 'TABLE_EXIST',
TABLE_NOT_EXIST = 'TABLE_NOT_EXIST',
COLUMN_EXIST = 'COLUMN_EXIST',
COLUMN_NOT_EXIST = 'COLUMN_NOT_EXIST',
CONSTRAINT_EXIST = 'CONSTRAINT_EXIST',
CONSTRAINT_NOT_EXIST = 'CONSTRAINT_NOT_EXIST',
COLUMN_NOT_NULL = 'COLUMN_NOT_NULL',
}
// extract db errors using database error code
function extractDBError(error): {
type: DBError;
message: string;
info: any;
extra?: Record<string, any>;
} | void {
if (!error.code) return;
let message: string;
let extra: Record<string, any>;
let type: DBError;
// todo: handle not null constraint error for all databases
switch (error.code) {
// sqlite errors
case 'SQLITE_BUSY':
message = 'The database is locked by another process or transaction.';
break;
case 'SQLITE_CONSTRAINT':
{
const constraint = /FOREIGN KEY|UNIQUE/.test(error.message)
? error.message.match(/FOREIGN KEY|UNIQUE/gi)?.join(' ')
: 'constraint';
message = `A ${constraint} constraint was violated: ${error.message}`;
extra = {
constraint,
};
}
break;
case 'SQLITE_CORRUPT':
message = 'The database file is corrupt.';
break;
case 'SQLITE_ERROR':
message = 'A SQL error occurred.';
if (error.message) {
const noSuchTableMatch = error.message.match(/no such table: (\w+)/);
const tableAlreadyExistsMatch = error.message.match(
/SQLITE_ERROR: table `?(\w+)`? already exists/,
);
const duplicateColumnExistsMatch = error.message.match(
/SQLITE_ERROR: duplicate column name: (\w+)/,
);
const unrecognizedTokenMatch = error.message.match(
/SQLITE_ERROR: unrecognized token: "(\w+)"/,
);
const columnDoesNotExistMatch = error.message.match(
/SQLITE_ERROR: no such column: (\w+)/,
);
const constraintFailedMatch = error.message.match(
/SQLITE_ERROR: constraint failed: (\w+)/,
);
if (noSuchTableMatch && noSuchTableMatch[1]) {
message = `The table '${noSuchTableMatch[1]}' does not exist.`;
type = DBError.TABLE_NOT_EXIST;
extra = {
table: noSuchTableMatch[1],
};
} else if (tableAlreadyExistsMatch && tableAlreadyExistsMatch[1]) {
message = `The table '${tableAlreadyExistsMatch[1]}' already exists.`;
type = DBError.TABLE_EXIST;
extra = {
table: tableAlreadyExistsMatch[1],
};
} else if (unrecognizedTokenMatch && unrecognizedTokenMatch[1]) {
message = `Unrecognized token: ${unrecognizedTokenMatch[1]}`;
extra = {
token: unrecognizedTokenMatch[1],
};
} else if (columnDoesNotExistMatch && columnDoesNotExistMatch[1]) {
message = `The column ${columnDoesNotExistMatch[1]} does not exist.`;
type = DBError.COLUMN_NOT_EXIST;
extra = {
column: columnDoesNotExistMatch[1],
};
} else if (constraintFailedMatch && constraintFailedMatch[1]) {
message = `A constraint failed: ${constraintFailedMatch[1]}`;
} else if (
duplicateColumnExistsMatch &&
duplicateColumnExistsMatch[1]
) {
message = `The column '${duplicateColumnExistsMatch[1]}' already exists.`;
type = DBError.COLUMN_EXIST;
extra = {
column: duplicateColumnExistsMatch[1],
};
} else {
const match = error.message.match(/SQLITE_ERROR:\s*(\w+)/);
if (match && match[1]) {
message = match[1];
}
}
}
break;
case 'SQLITE_RANGE':
message = 'A column index is out of range.';
break;
case 'SQLITE_SCHEMA':
message = 'The database schema has changed.';
break;
// mysql errors
case 'ER_TABLE_EXISTS_ERROR':
message = 'The table already exists.';
if (error.message) {
const extractTableNameMatch = error.message.match(
/ Table '?(\w+)'? already exists/i,
);
if (extractTableNameMatch && extractTableNameMatch[1]) {
message = `The table '${extractTableNameMatch[1]}' already exists.`;
type = DBError.TABLE_EXIST;
extra = {
table: extractTableNameMatch[1],
};
}
}
break;
case 'ER_DUP_FIELDNAME':
message = 'The column already exists.';
if (error.message) {
const extractColumnNameMatch = error.message.match(
/ Duplicate column name '(\w+)'/i,
);
if (extractColumnNameMatch && extractColumnNameMatch[1]) {
message = `The column '${extractColumnNameMatch[1]}' already exists.`;
type = DBError.COLUMN_EXIST;
extra = {
column: extractColumnNameMatch[1],
};
}
}
break;
case 'ER_NO_SUCH_TABLE':
message = 'The table does not exist.';
if (error.message) {
const missingTableMatch = error.message.match(
/ Table '(?:\w+\.)?(\w+)' doesn't exist/i,
);
if (missingTableMatch && missingTableMatch[1]) {
message = `The table '${missingTableMatch[1]}' does not exist`;
type = DBError.TABLE_NOT_EXIST;
extra = {
table: missingTableMatch[1],
};
}
}
break;
case 'ER_DUP_ENTRY':
message = 'This record already exists.';
break;
case 'ER_PARSE_ERROR':
message = 'There was a syntax error in your SQL query.';
break;
case 'ER_NO_DEFAULT_FOR_FIELD':
message = 'A value is required for this field.';
break;
case 'ER_BAD_NULL_ERROR':
message = 'A null value is not allowed for this field.';
{
const extractColNameMatch = error.message.match(
/Column '(\w+)' cannot be null/i,
);
if (extractColNameMatch && extractColNameMatch[1]) {
message = `The column '${extractColNameMatch[1]}' cannot be null.`;
type = DBError.COLUMN_NOT_NULL;
extra = {
column: extractColNameMatch[1],
};
}
}
break;
case 'ER_DATA_TOO_LONG':
message = 'The data entered is too long for this field.';
break;
case 'ER_BAD_FIELD_ERROR':
{
message = 'The field you are trying to access does not exist.';
const extractColNameMatch = error.message.match(
/ Unknown column '(\w+)' in 'field list'/i,
);
if (extractColNameMatch && extractColNameMatch[1]) {
message = `The column '${extractColNameMatch[1]}' does not exist.`;
type = DBError.COLUMN_NOT_EXIST;
extra = {
column: extractColNameMatch[1],
};
}
}
break;
case 'ER_ACCESS_DENIED_ERROR':
message = 'You do not have permission to perform this action.';
break;
case 'ER_LOCK_WAIT_TIMEOUT':
message = 'A timeout occurred while waiting for a table lock.';
break;
case 'ER_NO_REFERENCED_ROW':
message = 'The referenced row does not exist.';
break;
case 'ER_ROW_IS_REFERENCED':
message = 'This record is being referenced by other records.';
break;
// postgres errors
case '23505':
message = 'This record already exists.';
break;
case '42601':
message = 'There was a syntax error in your SQL query.';
break;
case '23502':
message = 'A value is required for this field.';
break;
case '23503':
message = 'The referenced row does not exist.';
break;
case '23514':
message = 'A null value is not allowed for this field.';
break;
case '22001':
message = 'The data entered is too long for this field.';
break;
case '28000':
message = 'You do not have permission to perform this action.';
break;
case '40P01':
message = 'A timeout occurred while waiting for a table lock.';
break;
case '23506':
message = 'This record is being referenced by other records.';
break;
case '42P07':
message = 'The table already exists.';
if (error.message) {
const extractTableNameMatch = error.message.match(
/ relation "?(\w+)"? already exists/i,
);
if (extractTableNameMatch && extractTableNameMatch[1]) {
message = `The table '${extractTableNameMatch[1]}' already exists.`;
type = DBError.TABLE_EXIST;
extra = {
table: extractTableNameMatch[1],
};
}
}
break;
case '42701':
message = 'The column already exists.';
if (error.message) {
const extractTableNameMatch = error.message.match(
/ column "(\w+)" of relation "(\w+)" already exists/i,
);
if (extractTableNameMatch && extractTableNameMatch[1]) {
message = `The column '${extractTableNameMatch[1]}' already exists.`;
type = DBError.COLUMN_EXIST;
extra = {
column: extractTableNameMatch[1],
};
}
}
break;
case '42P01':
message = 'The table does not exist.';
if (error.message) {
const extractTableNameMatch = error.message.match(
/ relation "(\w+)" does not exist/i,
);
if (extractTableNameMatch && extractTableNameMatch[1]) {
message = `The table '${extractTableNameMatch[1]}' does not exist.`;
type = DBError.TABLE_NOT_EXIST;
extra = {
table: extractTableNameMatch[1],
};
}
}
break;
case '42703':
message = 'The column does not exist.';
if (error.message) {
const extractTableNameMatch = error.message.match(
/ column "(\w+)" does not exist/i,
);
if (extractTableNameMatch && extractTableNameMatch[1]) {
message = `The column '${extractTableNameMatch[1]}' does not exist.`;
type = DBError.COLUMN_NOT_EXIST;
extra = {
column: extractTableNameMatch[1],
};
}
}
break;
// mssql errors
case 'EREQUEST':
message = 'There was a syntax error in your SQL query.';
if (error.message) {
const extractTableNameMatch = error.message.match(
/ There is already an object named '(\w+)' in the database/i,
);
const extractDupColMatch = error.message.match(
/ Column name '(\w+)' in table '(\w+)' is specified more than once/i,
);
const extractMissingTableMatch = error.message.match(
/ Invalid object name '(\w+)'./i,
);
const extractMissingColMatch = error.message.match(
/ Invalid column name '(\w+)'./i,
);
if (extractTableNameMatch && extractTableNameMatch[1]) {
message = `The table '${extractTableNameMatch[1]}' already exists.`;
type = DBError.TABLE_EXIST;
extra = {
table: extractTableNameMatch[1],
};
} else if (extractDupColMatch && extractDupColMatch[1]) {
message = `The column '${extractDupColMatch[1]}' already exists.`;
type = DBError.COLUMN_EXIST;
extra = {
column: extractDupColMatch[1],
};
} else if (extractMissingTableMatch && extractMissingTableMatch[1]) {
message = `The table '${extractMissingTableMatch[1]}' does not exist`;
type = DBError.TABLE_NOT_EXIST;
extra = {
table: extractMissingTableMatch[1],
};
} else if (extractMissingColMatch && extractMissingColMatch[1]) {
message = `The column '${extractMissingColMatch[1]}' does not exist`;
type = DBError.COLUMN_NOT_EXIST;
extra = {
column: extractMissingColMatch[1],
};
}
}
break;
case 'ELOGIN':
message = 'You do not have permission to perform this action.';
break;
case 'ETIMEOUT':
message = 'A timeout occurred while waiting for a table lock.';
break;
case 'ECONNRESET':
message = 'The connection was reset.';
break;
case 'ECONNREFUSED':
message = 'The connection was refused.';
break;
case 'EHOSTUNREACH':
message = 'The host is unreachable.';
break;
case 'EHOSTDOWN':
message = 'The host is down.';
break;
}
if (message) {
return {
message,
type,
extra,
info: { message: error.message, code: error.code },
};
}
}
export default function (
requestHandler: (req: any, res: any, next?: any) => any,
) {
return async function (req: any, res: any, next: any) {
try {
return await requestHandler(req, res, next);
} catch (e) {
// todo: error log
console.log(requestHandler.name ? `${requestHandler.name} ::` : '', e);
const dbError = extractDBError(e);
if (dbError) {
return res.status(400).json(dbError);
}
if (e instanceof BadRequest) {
return res.status(400).json({ msg: e.message });
} else if (e instanceof Unauthorized) {
return res.status(401).json({ msg: e.message });
} else if (e instanceof Forbidden) {
return res.status(403).json({ msg: e.message });
} else if (e instanceof NotFound) {
return res.status(404).json({ msg: e.message });
} else if (e instanceof InternalServerError) {
return res.status(500).json({ msg: e.message });
} else if (e instanceof NotImplemented) {
return res.status(501).json({ msg: e.message });
} else if (e instanceof AjvError) {
return res.status(400).json({ msg: e.message, errors: e.errors });
}
next(e);
}
};
}
class BadRequest extends Error {}
class Unauthorized extends Error {}
class Forbidden extends Error {}
class NotFound extends Error {}
class InternalServerError extends Error {}
class NotImplemented extends Error {}
class AjvError extends Error {
constructor(param: { message: string; errors: ErrorObject[] }) {
super(param.message);
this.errors = param.errors;
}
errors: ErrorObject[];
}
export class NcError {
static notFound(message = 'Not found') {
throw new NotFound(message);
}
static badRequest(message) {
throw new BadRequest(message);
}
static unauthorized(message) {
throw new Unauthorized(message);
}
static forbidden(message) {
throw new Forbidden(message);
}
static internalServerError(message = 'Internal server error') {
throw new InternalServerError(message);
}
static notImplemented(message = 'Not implemented') {
throw new NotImplemented(message);
}
static ajvValidationError(param: { message: string; errors: ErrorObject[] }) {
throw new AjvError(param);
}
}
// todo: remove this file
export * from '../helpers/catchError';
import catchError from '../helpers/catchError';
export default catchError;

5
packages/nocodb-nest/src/modules/api-tokens/api-tokens.controller.ts

@ -2,12 +2,12 @@ import {
Body,
Controller,
Delete,
Get,
Get, HttpCode,
Param,
Post,
Request,
UseGuards,
} from '@nestjs/common';
} from '@nestjs/common'
import { AuthGuard } from '@nestjs/passport';
import { PagedResponseImpl } from '../../helpers/PagedResponse';
import {
@ -30,6 +30,7 @@ export class ApiTokensController {
}
@Post('/api/v1/db/meta/projects/:projectId/api-tokens')
@HttpCode(200)
@Acl('apiTokenCreate')
async apiTokenCreate(@Request() req, @Body() body) {
return await this.apiTokensService.apiTokenCreate({

6
packages/nocodb-nest/src/modules/attachments/attachments.controller.ts

@ -2,7 +2,7 @@ import path from 'path';
import {
Body,
Controller,
Get,
Get, HttpCode,
Param,
Post,
Query,
@ -11,7 +11,7 @@ import {
UploadedFiles,
UseGuards,
UseInterceptors,
} from '@nestjs/common';
} from '@nestjs/common'
import multer from 'multer';
import { FileInterceptor, FilesInterceptor } from '@nestjs/platform-express';
import { OrgUserRoles, ProjectRoles } from 'nocodb-sdk';
@ -44,6 +44,7 @@ export class AttachmentsController {
// ]
// );
)
@HttpCode(200)
@UseInterceptors(
UploadAllowedInterceptor,
FilesInterceptor('files[]', null, {
@ -71,6 +72,7 @@ export class AttachmentsController {
}
@Post('/api/v1/db/storage/upload-by-url')
@HttpCode(200)
@UseInterceptors(UploadAllowedInterceptor)
// [
// extractProjectIdAndAuthenticate,

6
packages/nocodb-nest/src/modules/audits/audits.controller.ts

@ -1,14 +1,14 @@
import {
Body,
Controller,
Get,
Get, HttpCode,
Param,
Patch,
Post,
Query,
Request,
UseGuards,
} from '@nestjs/common';
} from '@nestjs/common'
import { AuthGuard } from '@nestjs/passport';
import { PagedResponseImpl } from '../../helpers/PagedResponse';
import {
@ -24,6 +24,7 @@ export class AuditsController {
constructor(private readonly auditsService: AuditsService) {}
@Post('/api/v1/db/meta/audits/comments')
@HttpCode(200)
@Acl('commentRow')
async commentRow(@Request() req) {
return await this.auditsService.commentRow({
@ -35,6 +36,7 @@ export class AuditsController {
}
@Post('/api/v1/db/meta/audits/rows/:rowId/update')
@HttpCode(200)
@Acl('auditRowUpdate')
async auditRowUpdate(@Param('rowId') rowId: string, @Body() body: any) {
return await this.auditsService.auditRowUpdate({

6
packages/nocodb-nest/src/modules/auth/auth.controller.ts

@ -1,11 +1,11 @@
import {
Body,
Controller,
Get,
Get, HttpCode,
Post,
Request,
UseGuards,
} from '@nestjs/common';
} from '@nestjs/common'
import { AuthGuard } from '@nestjs/passport';
import { ExtractProjectIdMiddleware } from '../../middlewares/extract-project-id/extract-project-id.middleware';
import extractRolesObj from '../../utils/extractRolesObj';
@ -23,11 +23,13 @@ export class AuthController {
@UseGuards(AuthGuard('local'))
@Post('/api/v1/auth/user/signin')
@HttpCode(200)
async signin(@Request() req) {
return this.authService.login(req.user);
}
@Post('/api/v1/auth/user/signup')
@HttpCode(200)
async signup(@Body() createUserDto: CreateUserDto) {
return await this.authService.signup(createUserDto);
}

5
packages/nocodb-nest/src/modules/bases/bases.controller.ts

@ -2,12 +2,12 @@ import {
Body,
Controller,
Delete,
Get,
Get, HttpCode,
Param,
Patch,
Post,
UseGuards,
} from '@nestjs/common';
} from '@nestjs/common'
import { BaseReqType } from 'nocodb-sdk';
import { AuthGuard } from '@nestjs/passport';
import { PagedResponseImpl } from '../../helpers/PagedResponse';
@ -71,6 +71,7 @@ export class BasesController {
}
@Post('/api/v1/db/meta/projects/:projectId/bases')
@HttpCode(200)
@Acl('baseCreate')
async baseCreate(
@Param('projectId') projectId: string,

6
packages/nocodb-nest/src/modules/columns/columns.controller.ts

@ -2,13 +2,13 @@ import {
Body,
Controller,
Delete,
Get,
Get, HttpCode,
Param,
Patch,
Post,
Request,
UseGuards,
} from '@nestjs/common';
} from '@nestjs/common'
import { ColumnReqType } from 'nocodb-sdk';
import { AuthGuard } from '@nestjs/passport';
import {
@ -23,6 +23,7 @@ export class ColumnsController {
constructor(private readonly columnsService: ColumnsService) {}
@Post('/api/v1/db/meta/tables/:tableId/columns/')
@HttpCode(200)
@Acl('columnAdd')
async columnAdd(
@Param('tableId') tableId: string,
@ -63,6 +64,7 @@ export class ColumnsController {
}
@Post('/api/v1/db/meta/columns/:columnId/primary')
@HttpCode(200)
@Acl('columnSetAsPrimary')
async columnSetAsPrimary(@Param('columnId') columnId: string) {
return await this.columnsService.columnSetAsPrimary({ columnId });

5
packages/nocodb-nest/src/modules/datas/bulk-data-alias/bulk-data-alias.controller.ts

@ -1,13 +1,13 @@
import {
Body,
Controller,
Delete,
Delete, HttpCode,
Param,
Patch,
Post,
Request,
UseGuards,
} from '@nestjs/common';
} from '@nestjs/common'
import { AuthGuard } from '@nestjs/passport';
import {
Acl,
@ -21,6 +21,7 @@ export class BulkDataAliasController {
constructor(private bulkDataAliasService: BulkDataAliasService) {}
@Post('/api/v1/db/data/bulk/:orgs/:projectName/:tableName')
@HttpCode(200)
@Acl('bulkDataInsert')
async bulkDataInsert(
@Request() req,

5
packages/nocodb-nest/src/modules/datas/data-alias.controller.ts

@ -2,14 +2,14 @@ import {
Body,
Controller,
Delete,
Get,
Get, HttpCode,
Param,
Patch,
Post,
Request,
Response,
UseGuards,
} from '@nestjs/common';
} from '@nestjs/common'
import { AuthGuard } from '@nestjs/passport';
import { parseHrtimeToSeconds } from '../../helpers';
import {
@ -112,6 +112,7 @@ export class DataAliasController {
'/api/v1/db/data/:orgs/:projectName/:tableName',
'/api/v1/db/data/:orgs/:projectName/:tableName/views/:viewName',
])
@HttpCode(200)
@Acl('dataInsert')
async dataInsert(
@Request() req,

6
packages/nocodb-nest/src/modules/datas/datas.controller.ts

@ -2,12 +2,12 @@ import {
Body,
Controller,
Delete,
Get,
Get, HttpCode,
Param,
Patch,
Post,
Request,
} from '@nestjs/common';
} from '@nestjs/common'
import { Acl } from '../../middlewares/extract-project-id/extract-project-id.middleware';
import { DatasService } from './datas.service';
@ -119,6 +119,7 @@ export class DatasController {
}
@Post('/data/:viewId/')
@HttpCode(200)
@Acl('dataInsert')
async dataInsert(
@Request() req,
@ -184,6 +185,7 @@ export class DatasController {
}
@Post('/data/:viewId/:rowId/:relationType/:colId/:childId')
@HttpCode(200)
@Acl('relationDataAdd')
async relationDataAdd(
@Request() req,

5
packages/nocodb-nest/src/modules/datas/old-datas/old-datas.controller.ts

@ -2,14 +2,14 @@ import {
Body,
Controller,
Delete,
Get,
Get, HttpCode,
Param,
Patch,
Post,
Request,
Response,
UseGuards,
} from '@nestjs/common';
} from '@nestjs/common'
import { AuthGuard } from '@nestjs/passport';
import {
Acl,
@ -57,6 +57,7 @@ export class OldDatasController {
}
@Post('/nc/:projectId/api/v1/:tableName')
@HttpCode(200)
@Acl('dataInsert')
async dataInsert(
@Request() req,

6
packages/nocodb-nest/src/modules/filters/filters.controller.ts

@ -2,12 +2,12 @@ import {
Body,
Controller,
Delete,
Get,
Get, HttpCode,
Param,
Patch,
Post,
UseGuards,
} from '@nestjs/common';
} from '@nestjs/common'
import { AuthGuard } from '@nestjs/passport';
import { FilterReqType } from 'nocodb-sdk';
import { PagedResponseImpl } from '../../helpers/PagedResponse';
@ -34,6 +34,7 @@ export class FiltersController {
}
@Post('/api/v1/db/meta/views/:viewId/filters')
@HttpCode(200)
@Acl('filterCreate')
async filterCreate(
@Param('viewId') viewId: string,
@ -47,6 +48,7 @@ export class FiltersController {
}
@Post('/api/v1/db/meta/hooks/:hookId/filters')
@HttpCode(200)
@Acl('hookFilterCreate')
async hookFilterCreate(
@Param('hookId') hookId: string,

5
packages/nocodb-nest/src/modules/forms/forms.controller.ts

@ -1,12 +1,12 @@
import {
Body,
Controller,
Get,
Get, HttpCode,
Param,
Patch,
Post,
UseGuards,
} from '@nestjs/common';
} from '@nestjs/common'
import { ViewCreateReqType } from 'nocodb-sdk';
import { AuthGuard } from '@nestjs/passport';
import {
@ -30,6 +30,7 @@ export class FormsController {
}
@Post('/api/v1/db/meta/tables/:tableId/forms')
@HttpCode(200)
@Acl('formViewCreate')
async formViewCreate(
@Param('tableId') tableId: string,

5
packages/nocodb-nest/src/modules/galleries/galleries.controller.ts

@ -1,12 +1,12 @@
import {
Body,
Controller,
Get,
Get, HttpCode,
Param,
Patch,
Post,
UseGuards,
} from '@nestjs/common';
} from '@nestjs/common'
import { GalleryUpdateReqType, ViewCreateReqType } from 'nocodb-sdk';
import { AuthGuard } from '@nestjs/passport';
import {
@ -29,6 +29,7 @@ export class GalleriesController {
}
@Post('/api/v1/db/meta/tables/:tableId/galleries')
@HttpCode(200)
@Acl('galleryViewCreate')
async galleryViewCreate(
@Param('tableId') tableId: string,

5
packages/nocodb-nest/src/modules/grids/grids.controller.ts

@ -1,11 +1,11 @@
import {
Body,
Controller,
Controller, HttpCode,
Param,
Patch,
Post,
UseGuards,
} from '@nestjs/common';
} from '@nestjs/common'
import { ViewCreateReqType } from 'nocodb-sdk';
import { AuthGuard } from '@nestjs/passport';
import {
@ -23,6 +23,7 @@ export class GridsController {
constructor(private readonly gridsService: GridsService) {}
@Post('/api/v1/db/meta/tables/:tableId/grids/')
@HttpCode(200)
@Acl('gridViewCreate')
async gridViewCreate(
@Param('tableId') tableId: string,

6
packages/nocodb-nest/src/modules/hooks/hooks.controller.ts

@ -2,13 +2,13 @@ import {
Body,
Controller,
Delete,
Get,
Get, HttpCode,
Param,
Patch,
Post,
Request,
UseGuards,
} from '@nestjs/common';
} from '@nestjs/common'
import { HookReqType, HookTestReqType } from 'nocodb-sdk';
import { AuthGuard } from '@nestjs/passport';
import { PagedResponseImpl } from '../../helpers/PagedResponse';
@ -31,6 +31,7 @@ export class HooksController {
}
@Post('/api/v1/db/meta/tables/:tableId/hooks')
@HttpCode(200)
@Acl('hookCreate')
async hookCreate(
@Param('tableId') tableId: string,
@ -57,6 +58,7 @@ export class HooksController {
}
@Post('/api/v1/db/meta/tables/:tableId/hooks/test')
@HttpCode(200)
@Acl('hookTest')
async hookTest(@Body() body: HookTestReqType, @Request() req: any) {
try {

5
packages/nocodb-nest/src/modules/import/import.controller.ts

@ -1,4 +1,4 @@
import { Controller, Post, Request } from '@nestjs/common';
import { Controller, HttpCode, Post, Request } from '@nestjs/common'
import { forwardRef, Inject } from '@nestjs/common';
import { ModuleRef } from '@nestjs/core';
import { NcError } from '../../helpers/catchError';
@ -88,6 +88,7 @@ export class ImportController {
) {}
@Post('/api/v1/db/meta/import/airtable')
@HttpCode(200)
importAirtable(@Request() req) {
NocoJobs.jobsMgr.add(AIRTABLE_IMPORT_JOB, {
id: req.query.id,
@ -97,6 +98,7 @@ export class ImportController {
}
@Post('/api/v1/db/meta/syncs/:syncId/trigger')
@HttpCode(200)
async triggerSync(@Request() req) {
if (req.params.syncId in jobs) {
NcError.badRequest('Sync already in progress');
@ -137,6 +139,7 @@ export class ImportController {
}
@Post('/api/v1/db/meta/syncs/:syncId/abort')
@HttpCode(200)
async abortImport(@Request() req) {
if (req.params.syncId in jobs) {
delete jobs[req.params.syncId];

5
packages/nocodb-nest/src/modules/kanbans/kanbans.controller.ts

@ -1,12 +1,12 @@
import {
Body,
Controller,
Get,
Get, HttpCode,
Param,
Patch,
Post,
UseGuards,
} from '@nestjs/common';
} from '@nestjs/common'
import { ViewCreateReqType } from 'nocodb-sdk';
import { AuthGuard } from '@nestjs/passport';
import {
@ -29,6 +29,7 @@ export class KanbansController {
}
@Post('/api/v1/db/meta/tables/:tableId/kanbans')
@HttpCode(200)
@Acl('kanbanViewCreate')
async kanbanViewCreate(
@Param('tableId') tableId: string,

5
packages/nocodb-nest/src/modules/maps/maps.controller.ts

@ -1,12 +1,12 @@
import {
Body,
Controller,
Get,
Get, HttpCode,
Param,
Patch,
Post,
UseGuards,
} from '@nestjs/common';
} from '@nestjs/common'
import { MapUpdateReqType, ViewCreateReqType } from 'nocodb-sdk';
import { AuthGuard } from '@nestjs/passport';
import {
@ -27,6 +27,7 @@ export class MapsController {
}
@Post('/api/v1/db/meta/tables/:tableId/maps')
@HttpCode(200)
@Acl('mapViewCreate')
async mapViewCreate(
@Param('tableId') tableId: string,

4
packages/nocodb-nest/src/modules/meta-diffs/meta-diffs.controller.ts

@ -1,4 +1,4 @@
import { Controller, Get, Param, Post, UseGuards } from '@nestjs/common';
import { Controller, Get, HttpCode, Param, Post, UseGuards } from '@nestjs/common'
import { AuthGuard } from '@nestjs/passport';
import {
Acl,
@ -29,6 +29,7 @@ export class MetaDiffsController {
}
@Post('/api/v1/db/meta/projects/:projectId/meta-diff')
@HttpCode(200)
@Acl('metaDiffSync')
async metaDiffSync(@Param('projectId') projectId: string) {
await this.metaDiffsService.metaDiffSync({ projectId });
@ -36,6 +37,7 @@ export class MetaDiffsController {
}
@Post('/api/v1/db/meta/projects/:projectId/meta-diff/:baseId')
@HttpCode(200)
@Acl('baseMetaDiffSync')
async baseMetaDiffSync(
@Param('projectId') projectId: string,

5
packages/nocodb-nest/src/modules/model-visibilities/model-visibilities.controller.ts

@ -1,12 +1,12 @@
import {
Body,
Controller,
Get,
Get, HttpCode,
Param,
Post,
Query,
UseGuards,
} from '@nestjs/common';
} from '@nestjs/common'
import { AuthGuard } from '@nestjs/passport';
import {
Acl,
@ -22,6 +22,7 @@ export class ModelVisibilitiesController {
) {}
@Post('/api/v1/db/meta/projects/:projectId/visibility-rules')
@HttpCode(200)
@Acl('modelVisibilitySet')
async xcVisibilityMetaSetAll(
@Param('projectId') projectId: string,

3
packages/nocodb-nest/src/modules/org-lcense/org-lcense.controller.ts

@ -1,4 +1,4 @@
import { Controller, Get, Post } from '@nestjs/common';
import { Controller, Get, HttpCode, Post } from '@nestjs/common'
import { OrgUserRoles } from 'nocodb-sdk';
import { Acl } from '../../middlewares/extract-project-id/extract-project-id.middleware';
import { OrgLcenseService } from './org-lcense.service';
@ -17,6 +17,7 @@ export class OrgLcenseController {
}
@Post('/api/v1/license')
@HttpCode(200)
@Acl('licenseSet', {
allowedRoles: [OrgUserRoles.SUPER_ADMIN],
blockApiTokenAccess: true,

5
packages/nocodb-nest/src/modules/org-tokens/org-tokens.controller.ts

@ -2,12 +2,12 @@ import {
Body,
Controller,
Delete,
Get,
Get, HttpCode,
Param,
Post,
Request,
UseGuards,
} from '@nestjs/common';
} from '@nestjs/common'
import { ApiTokenReqType } from 'nocodb-sdk';
import { AuthGuard } from '@nestjs/passport';
import { getConditionalHandler } from '../../helpers/getHandler';
@ -41,6 +41,7 @@ export class OrgTokensController {
}
@Post('/api/v1/tokens')
@HttpCode(200)
@Acl('apiTokenCreate', {
blockApiTokenAccess: true,
})

9
packages/nocodb-nest/src/modules/org-users/org-users.controller.ts

@ -2,12 +2,12 @@ import {
Body,
Controller,
Delete,
Get,
Get, HttpCode,
Param,
Patch,
Post,
Request,
} from '@nestjs/common';
} from '@nestjs/common'
import { OrgUserRoles } from 'nocodb-sdk';
import { PagedResponseImpl } from '../../helpers/PagedResponse';
import { Acl } from '../../middlewares/extract-project-id/extract-project-id.middleware';
@ -62,6 +62,7 @@ export class OrgUsersController {
}
@Post('/api/v1/users')
@HttpCode(200)
@Acl('userAdd', {
allowedRoles: [OrgUserRoles.SUPER_ADMIN],
blockApiTokenAccess: true,
@ -81,6 +82,7 @@ export class OrgUsersController {
}
@Post('/api/v1/users/settings')
@HttpCode(200)
@Acl('userSettings', {
allowedRoles: [OrgUserRoles.SUPER_ADMIN],
blockApiTokenAccess: true,
@ -91,6 +93,7 @@ export class OrgUsersController {
}
@Post('/api/v1/users/:userId/resend-invite')
@HttpCode(200)
@Acl('userInviteResend', {
allowedRoles: [OrgUserRoles.SUPER_ADMIN],
blockApiTokenAccess: true,
@ -108,6 +111,7 @@ export class OrgUsersController {
}
@Post('/api/v1/users/:userId/generate-reset-url')
@HttpCode(200)
@Acl('generateResetUrl', {
allowedRoles: [OrgUserRoles.SUPER_ADMIN],
blockApiTokenAccess: true,
@ -132,6 +136,7 @@ export class OrgUsersController {
}
@Post('/api/v1/app-settings')
@HttpCode(200)
@Acl('appSettingsSet', {
allowedRoles: [OrgUserRoles.SUPER_ADMIN],
blockApiTokenAccess: true,

3
packages/nocodb-nest/src/modules/plugins/plugins.controller.ts

@ -1,4 +1,4 @@
import { Body, Controller, Get, Param, Patch, Post } from '@nestjs/common';
import { Body, Controller, Get, HttpCode, Param, Patch, Post } from '@nestjs/common'
import { PagedResponseImpl } from '../../helpers/PagedResponse';
import { Acl } from '../../middlewares/extract-project-id/extract-project-id.middleware';
import { PluginsService } from './plugins.service';
@ -21,6 +21,7 @@ export class PluginsController {
}
@Post('/api/v1/db/meta/plugins/test')
@HttpCode(200)
@Acl('pluginTest')
async pluginTest(@Body() body: any) {
return await this.pluginsService.pluginTest({ body: body });

6
packages/nocodb-nest/src/modules/project-users/project-users.controller.ts

@ -2,13 +2,13 @@ import {
Body,
Controller,
Delete,
Get,
Get, HttpCode,
Param,
Patch,
Post,
Request,
UseGuards,
} from '@nestjs/common';
} from '@nestjs/common'
import { ProjectUserReqType } from 'nocodb-sdk';
import { AuthGuard } from '@nestjs/passport';
import {
@ -34,6 +34,7 @@ export class ProjectUsersController {
}
@Post('/api/v1/db/meta/projects/:projectId/users')
@HttpCode(200)
@Acl('userInvite')
async userInvite(
@Param('projectId') projectId: string,
@ -86,6 +87,7 @@ export class ProjectUsersController {
}
@Post('/api/v1/db/meta/projects/:projectId/users/:userId/resend-invite')
@HttpCode(200)
@Acl('projectUserInviteResend')
async projectUserInviteResend(
@Param('projectId') projectId: string,

5
packages/nocodb-nest/src/modules/projects/projects.controller.ts

@ -2,14 +2,14 @@ import {
Body,
Controller,
Delete,
Get,
Get, HttpCode,
Param,
Patch,
Post,
Query,
Request,
UseGuards,
} from '@nestjs/common';
} from '@nestjs/common'
import { AuthGuard } from '@nestjs/passport';
import isDocker from 'is-docker';
import { ProjectReqType } from 'nocodb-sdk';
@ -90,6 +90,7 @@ export class ProjectsController {
}
@Post('/api/v1/db/meta/projects')
@HttpCode(200)
async projectCreate(@Body() projectBody: ProjectReqType, @Request() req) {
const project = await this.projectsService.projectCreate({
project: projectBody,

3
packages/nocodb-nest/src/modules/public-datas/public-datas.controller.ts

@ -1,4 +1,4 @@
import { Controller, Get, Param, Post, Request } from '@nestjs/common';
import { Controller, Get, HttpCode, Param, Post, Request } from '@nestjs/common'
import { PublicDatasService } from './public-datas.service';
@Controller()
@ -46,6 +46,7 @@ export class PublicDatasController {
// catchError(dataInsert)
// );
@Post('/api/v1/db/public/shared-view/:sharedViewUuid/rows')
@HttpCode(200)
async dataInsert(
@Request() req,
@Param('sharedViewUuid') sharedViewUuid: string,

5
packages/nocodb-nest/src/modules/shared-bases/shared-bases.controller.ts

@ -2,13 +2,13 @@ import {
Body,
Controller,
Delete,
Get,
Get, HttpCode,
Param,
Patch,
Post,
Request,
UseGuards,
} from '@nestjs/common';
} from '@nestjs/common'
import { AuthGuard } from '@nestjs/passport';
import {
Acl,
@ -22,6 +22,7 @@ export class SharedBasesController {
constructor(private readonly sharedBasesService: SharedBasesService) {}
@Post('/api/v1/db/meta/projects/:projectId/shared')
@HttpCode(200)
@Acl('createSharedBaseLink')
async createSharedBaseLink(
@Request() req,

5
packages/nocodb-nest/src/modules/sorts/sorts.controller.ts

@ -2,12 +2,12 @@ import {
Body,
Controller,
Delete,
Get,
Get, HttpCode,
Param,
Patch,
Post,
UseGuards,
} from '@nestjs/common';
} from '@nestjs/common'
import { AuthGuard } from '@nestjs/passport';
import { SortReqType } from 'nocodb-sdk';
import { PagedResponseImpl } from '../../helpers/PagedResponse';
@ -35,6 +35,7 @@ export class SortsController {
}
@Post('/api/v1/db/meta/views/:viewId/sorts/')
@HttpCode(200)
@UseAclMiddleware({
permissionName: 'sortCreate',
})

5
packages/nocodb-nest/src/modules/sync/sync.controller.ts

@ -2,12 +2,12 @@ import {
Body,
Controller,
Delete,
Get,
Get, HttpCode,
Param,
Patch,
Post,
Req,
} from '@nestjs/common';
} from '@nestjs/common'
import { Acl } from '../../middlewares/extract-project-id/extract-project-id.middleware';
import { SyncService } from './sync.service';
@ -34,6 +34,7 @@ export class SyncController {
'/api/v1/db/meta/projects/:projectId/syncs',
'/api/v1/db/meta/projects/:projectId/syncs/:baseId',
])
@HttpCode(200)
@Acl('syncSourceCreate')
async syncCreate(
@Param('projectId') projectId: string,

6
packages/nocodb-nest/src/modules/tables/tables.controller.ts

@ -2,14 +2,14 @@ import {
Body,
Controller,
Delete,
Get,
Get, HttpCode,
Param,
Patch,
Post,
Query,
Request,
UseGuards,
} from '@nestjs/common';
} from '@nestjs/common'
import { AuthGuard } from '@nestjs/passport';
import { TableReqType } from 'nocodb-sdk';
import extractRolesObj from '../../utils/extractRolesObj';
@ -52,6 +52,7 @@ export class TablesController {
'/api/v1/db/meta/projects/:projectId/tables',
'/api/v1/db/meta/projects/:projectId/:baseId/tables',
])
@HttpCode(200)
@UseAclMiddleware({
permissionName: 'tableCreate',
})
@ -119,6 +120,7 @@ export class TablesController {
@UseAclMiddleware({
permissionName: 'tableReorder',
})
@HttpCode(200)
async tableReorder(
@Param('tableId') tableId: string,
@Body() body: { order: number },

3
packages/nocodb-nest/src/modules/test/test.controller.ts

@ -1,4 +1,4 @@
import { Controller, Post, Req } from '@nestjs/common';
import { Controller, HttpCode, Post, Req } from '@nestjs/common'
import { TestService } from './test.service';
import { TestResetService } from './TestResetService';
@ -7,6 +7,7 @@ export class TestController {
constructor(private readonly testService: TestService) {}
@Post('/api/v1/meta/test/reset')
@HttpCode(200)
async reset(@Req() req) {
const service = new TestResetService({
parallelId: req.body.parallelId,

6
packages/nocodb-nest/src/modules/users/users.controller.ts

@ -49,6 +49,7 @@ export class UsersController {
'/api/v1/db/auth/token/refresh',
'/api/v1/auth/token/refresh',
])
@HttpCode(200)
async refreshToken(@Request() req: any, @Request() res: any): Promise<any> {
return await this.usersService.refreshToken({
body: req.body,
@ -113,6 +114,7 @@ export class UsersController {
}
@Post(`/auth/google/genTokenByCode`)
@HttpCode(200)
async googleSignin(req, res, next) {
// todo
/* passport.authenticate(
@ -179,6 +181,7 @@ export class UsersController {
'/api/v1/db/auth/password/forgot',
'/api/v1/auth/password/forgot',
])
@HttpCode(200)
async passwordForgot(@Request() req: any, @Body() body: any): Promise<any> {
await this.usersService.passwordForgot({
siteUrl: (req as any).ncSiteUrl,
@ -194,6 +197,7 @@ export class UsersController {
'/api/v1/db/auth/token/validate/:tokenId',
'/api/v1/auth/token/validate/:tokenId',
])
@HttpCode(200)
async tokenValidate(@Param('tokenId') tokenId: string): Promise<any> {
await this.usersService.tokenValidate({
token: tokenId,
@ -206,6 +210,7 @@ export class UsersController {
'/api/v1/db/auth/password/reset/:tokenId',
'/api/v1/auth/password/reset/:tokenId',
])
@HttpCode(200)
async passwordReset(
@Request() req: any,
@Param('tokenId') tokenId: string,
@ -224,6 +229,7 @@ export class UsersController {
'/api/v1/db/auth/email/validate/:tokenId',
'/api/v1/auth/email/validate/:tokenId',
])
@HttpCode(200)
async emailVerification(
@Request() req: any,
@Param('tokenId') tokenId: string,

7
packages/nocodb-nest/src/modules/utils/utils.controller.ts

@ -1,11 +1,11 @@
import {
Body,
Controller,
Get,
Get, HttpCode,
Post,
Request,
UseGuards,
} from '@nestjs/common';
} from '@nestjs/common'
import { AuthGuard } from '@nestjs/passport';
import {
Acl,
@ -32,6 +32,7 @@ export class UtilsController {
@UseGuards(ExtractProjectIdMiddleware, AuthGuard('jwt'))
@Post('/api/v1/db/meta/connection/test')
@Acl('testConnection')
@HttpCode(200)
async testConnection(@Body() body: any) {
return await this.utilsService.testConnection({ body });
}
@ -50,11 +51,13 @@ export class UtilsController {
}
@Post('/api/v1/db/meta/axiosRequestMake')
@HttpCode(200)
async axiosRequestMake(@Body() body: any) {
return await this.utilsService.axiosRequestMake({ body });
}
@Post('/api/v1/url_to_config')
@HttpCode(200)
async urlToDbConfig(@Body() body: any) {
return await this.utilsService.urlToDbConfig({
body,

5
packages/nocodb-nest/src/modules/view-columns/view-columns.controller.ts

@ -1,12 +1,12 @@
import {
Body,
Controller,
Get,
Get, HttpCode,
Param,
Patch,
Post,
UseGuards,
} from '@nestjs/common';
} from '@nestjs/common'
import { ColumnReqType, ViewColumnReqType } from 'nocodb-sdk';
import { AuthGuard } from '@nestjs/passport';
import { PagedResponseImpl } from '../../helpers/PagedResponse';
@ -30,6 +30,7 @@ export class ViewColumnsController {
}
@Post('/api/v1/db/meta/views/:viewId/columns/')
@HttpCode(200)
@Acl('columnAdd')
async columnAdd(
@Param('viewId') viewId: string,

7
packages/nocodb-nest/src/modules/views/views.controller.ts

@ -2,14 +2,14 @@ import {
Body,
Controller,
Delete,
Get,
Get, HttpCode,
Param,
Patch,
Post,
Query,
Request,
UseGuards,
} from '@nestjs/common';
} from '@nestjs/common'
import { ViewUpdateReqType } from 'nocodb-sdk';
import { PagedResponseImpl } from '../../helpers/PagedResponse';
import {
@ -62,6 +62,7 @@ export class ViewsController {
}
@Post('/api/v1/db/meta/views/:viewId/show-all')
@HttpCode(200)
@UseAclMiddleware({
permissionName: 'showAllColumns',
})
@ -75,6 +76,7 @@ export class ViewsController {
});
}
@Post('/api/v1/db/meta/views/:viewId/hide-all')
@HttpCode(200)
@UseAclMiddleware({
permissionName: 'hideAllColumns',
})
@ -89,6 +91,7 @@ export class ViewsController {
}
@Post('/api/v1/db/meta/views/:viewId/share')
@HttpCode(200)
@UseAclMiddleware({
permissionName: 'shareView',
})

Loading…
Cancel
Save