π₯ π₯ π₯ A Free & Self-hostable Airtable Alternative
TypeScript airtableairtable-alternativeautomatic-apihacktoberfestlow-codeno-codeno-code-databaseno-code-platformpostgresqlrest-apirestful-apispreadsheetsqliteswagger
prototype column update
Fendy Heryantodc761e414e0c
diff --git a/packages/nocodb/src/middlewares/extract-ids/extract-ids.middleware.ts b/packages/nocodb/src/middlewares/extract-ids/extract-ids.middleware.tsindex 008dfc208d..6c4bfa999f 100644--- a/packages/nocodb/src/middlewares/extract-ids/extract-ids.middleware.ts+++ b/packages/nocodb/src/middlewares/extract-ids/extract-ids.middleware.ts@@ -212,7 +212,7 @@ export class ExtractIdsMiddleware implements NestMiddleware, CanActivate {const hook = await Hook.get(context, params.hookId);if (!hook) {- NcError.hookNotFound(params.hookId);+ NcError.get(context).hookNotFound(params.hookId);}req.ncBaseId = hook.base_id;@@ -224,7 +224,7 @@ export class ExtractIdsMiddleware implements NestMiddleware, CanActivate {);if (!gridViewColumn) {- NcError.fieldNotFound(params.gridViewColumnId);+ NcError.get(context).fieldNotFound(params.gridViewColumnId);}req.ncBaseId = gridViewColumn.base_id;@@ -236,7 +236,7 @@ export class ExtractIdsMiddleware implements NestMiddleware, CanActivate {);if (!formViewColumn) {- NcError.fieldNotFound(params.formViewColumnId);+ NcError.get(context).fieldNotFound(params.formViewColumnId);}req.ncBaseId = formViewColumn.base_id;@@ -248,7 +248,7 @@ export class ExtractIdsMiddleware implements NestMiddleware, CanActivate {);if (!galleryViewColumn) {- NcError.fieldNotFound(params.galleryViewColumnId);+ NcError.get(context).fieldNotFound(params.galleryViewColumnId);}req.ncBaseId = galleryViewColumn.base_id;@@ -257,7 +257,7 @@ export class ExtractIdsMiddleware implements NestMiddleware, CanActivate {const column = await Column.get(context, { colId: params.columnId });if (!column) {- NcError.fieldNotFound(params.columnId);+ NcError.get(context).fieldNotFound(params.columnId);}req.ncBaseId = column.base_id;diff --git a/packages/nocodb/src/services/columns.service.ts b/packages/nocodb/src/services/columns.service.tsindex d578e58526..bd1ee5b05c 100644--- a/packages/nocodb/src/services/columns.service.ts+++ b/packages/nocodb/src/services/columns.service.ts@@ -323,8 +323,8 @@ export class ColumnsService implements IColumnsService {}),);- if (table.synced && column.readonly) {- NcError.badRequest(+ if (table.synced && column.readonly && !param.forceUpdateSystem) {+ NcError.get(context).invalidRequestBody(`The column '${column.title || column.column_name}' is a synced column and cannot be updated.`,@@ -430,13 +430,13 @@ export class ColumnsService implements IColumnsService {param.column.column_name &¶m.column.column_name.length > mxColumnLength) {- NcError.badRequest(+ NcError.get(context).invalidRequestBody(`Column name ${param.column.column_name} exceeds ${mxColumnLength} characters`,);}if (param.column.title && param.column.title.length > 255) {- NcError.badRequest(+ NcError.get(context).invalidRequestBody(`Column title ${param.column.title} exceeds 255 characters`,);}@@ -452,7 +452,7 @@ export class ColumnsService implements IColumnsService {exclude_id: param.columnId,}))) {- NcError.badRequest('Duplicate column name');+ NcError.get(context).invalidRequestBody('Duplicate column name');}if (param.column.title &&@@ -463,7 +463,7 @@ export class ColumnsService implements IColumnsService {}))) {// This error will be thrown if there are more than one column linking to the same table. You have to delete one of them- NcError.badRequest(+ NcError.get(context).invalidRequestBody(`Duplicate column alias for table ${table.title} and column is ${param.column.title}. Please change the name of this column and retry.`,);}diff --git a/packages/nocodb/src/services/v3/columns-v3.service.ts b/packages/nocodb/src/services/v3/columns-v3.service.tsindex c72dd1c0d2..baf1484fc6 100644--- a/packages/nocodb/src/services/v3/columns-v3.service.ts+++ b/packages/nocodb/src/services/v3/columns-v3.service.ts@@ -37,6 +37,7 @@ export class ColumnsV3Service {'swagger-v3.json#/components/schemas/FieldUpdate',param.column,true,+ context,);let column = await Column.get(context, { colId: param.columnId });diff --git a/packages/nocodb/tests/unit/rest/tests/metaApiV3/error-handling/column.test.ts b/packages/nocodb/tests/unit/rest/tests/metaApiV3/error-handling/column.test.tsindex 894d20be94..131c1122d2 100644--- a/packages/nocodb/tests/unit/rest/tests/metaApiV3/error-handling/column.test.ts+++ b/packages/nocodb/tests/unit/rest/tests/metaApiV3/error-handling/column.test.ts@@ -4,7 +4,7 @@ import request from 'supertest';import init from '../../../../init';export default function () {- describe.only('error-handling: Column v3', () => {+ describe('error-handling: Column v3', () => {let context: Awaited<ReturnType<typeof init>>;let initBase: any;let API_PREFIX: string;@@ -85,7 +85,7 @@ export default function () {});});- describe('column update', () => {+ describe.only('column update', () => {let column: any;beforeEach(async () => {const colResult = await request(context.app)@@ -95,14 +95,15 @@ export default function () {.expect(200);column = colResult.body;});- it('will handle column not found', async () => {+ it.only('will handle column not found', async () => {const result = await request(context.app).patch(`${API_PREFIX}/fields/NOT_FOUND`).set('xc-token', context.xc_token).send({ title: 'any' })- .expect(422);- expect(result.body.error).to.eq('COLUMN_NOT_FOUND');- expect(result.body.message).to.include(`Column 'NOT_FOUND' not found`);+ .expect(400);+ console.log(result.body)+ expect(result.body.error).to.eq('FIELD_NOT_FOUND');+ expect(result.body.message).to.include(`Field 'NOT_FOUND' not found`);});it('will handle duplicate alias', async () => {await request(context.app)@@ -116,7 +117,7 @@ export default function () {.send({ title: 'AnotherColumn' }).expect(400);expect(result.body.error).to.eq('INVALID_REQUEST_BODY');- expect(result.body.message).to.include('Duplicate column alias');+ expect(result.body.message).to.include('Invalid request body');});it('will handle incorrect title length', async () => {const longTitle = 'a'.repeat(300);@@ -126,7 +127,16 @@ export default function () {.send({ title: longTitle }).expect(400);expect(result.body.error).to.eq('INVALID_REQUEST_BODY');- expect(result.body.message).to.include('exceeds 255 characters');+ expect(result.body.message).to.include('Invalid request body');+ });+ it('will handle uidt incorrect', async () => {+ const result = await request(context.app)+ .patch(`${API_PREFIX}/fields/${column.id}`)+ .set('xc-token', context.xc_token)+ .send({ uidt: 'NotFoundUIDT' })+ .expect(400);+ expect(result.body.error).to.eq('INVALID_REQUEST_BODY');+ expect(result.body.message).to.include('Invalid request body');});});