Skip to content

πŸ”₯ πŸ”₯ πŸ”₯ A Free & Self-hostable Airtable Alternative

handle column delete

Fendy Heryanto35167e004946
diff --git a/packages/nocodb/src/schema/swagger-v3.json b/packages/nocodb/src/schema/swagger-v3.json
index c1bcae1de9..02fcf5f176 100644
--- a/packages/nocodb/src/schema/swagger-v3.json
+++ b/packages/nocodb/src/schema/swagger-v3.json
@@ -5615,6 +5615,42 @@
},
"type": {
"type": "string",
+ "enum": [
+ "SingleLineText",
+ "LongText",
+ "PhoneNumber",
+ "URL",
+ "Email",
+ "Number",
+ "Decimal",
+ "Currency",
+ "Percent",
+ "Duration",
+ "Date",
+ "DateTime",
+ "Time",
+ "SingleSelect",
+ "MultiSelect",
+ "Rating",
+ "Checkbox",
+ "Attachment",
+ "Geometry",
+ "Links",
+ "Lookup",
+ "Rollup",
+ "Button",
+ "Formula",
+ "Barcode",
+ "Year",
+ "QrCode",
+ "CreatedAt",
+ "LastModifiedAt",
+ "CreatedBy",
+ "LastModifiedBy",
+ "LinkToAnotherRecord",
+ "User",
+ "JSON"
+ ],
"description": "Field data type."
},
"description": {
@@ -5641,7 +5677,8 @@
"allOf": [
{
"$ref": "#/components/schemas/FieldBase"
- }, {
+ },
+ {
"required": [
"title",
"type"
diff --git a/packages/nocodb/src/services/columns.service.ts b/packages/nocodb/src/services/columns.service.ts
index 055d0a75a4..b8e9ecff73 100644
--- a/packages/nocodb/src/services/columns.service.ts
+++ b/packages/nocodb/src/services/columns.service.ts
@@ -2690,6 +2690,10 @@ export class ColumnsService implements IColumnsService {
const column = await Column.get(context, { colId: param.columnId }, ncMeta);
+ if (!column) {
+ NcError.get(context).fieldNotFound(param.columnId);
+ }
+
const { applyRowColorInvolvement } =
await this.viewRowColorService.checkIfColumnInvolved({
context,
@@ -2698,7 +2702,7 @@ export class ColumnsService implements IColumnsService {
});
if ((column.system || isSystemColumn(column)) && !param.forceDeleteSystem) {
- NcError.badRequest(
+ NcError.get(context).invalidRequestBody(
`The column '${
column.title || column.column_name
}' is a system column and cannot be deleted.`,
@@ -2723,11 +2727,11 @@ export class ColumnsService implements IColumnsService {
source?.is_schema_readonly &&
!readonlyMetaAllowedTypes.includes(column.uidt)
) {
- NcError.sourceMetaReadOnly(source.alias);
+ NcError.get(context).sourceMetaReadOnly(source.alias);
}
if (table.synced && column.readonly && !param.forceDeleteSystem) {
- NcError.badRequest(
+ NcError.get(context).invalidRequestBody(
`The column '${
column.title || column.column_name
}' is a synced column and cannot be deleted.`,
diff --git a/packages/nocodb/src/services/v3/columns-v3.service.ts b/packages/nocodb/src/services/v3/columns-v3.service.ts
index d8bafcd81c..73d58f4f9f 100644
--- a/packages/nocodb/src/services/v3/columns-v3.service.ts
+++ b/packages/nocodb/src/services/v3/columns-v3.service.ts
@@ -40,6 +40,15 @@ export class ColumnsV3Service {
context,
);
+ if (param.column.type) {
+ validatePayload(
+ `swagger-v3.json#/components/schemas/FieldOptions/${param.column.type}`,
+ param.column,
+ true,
+ context,
+ );
+ }
+
let column = await Column.get(context, { colId: param.columnId });
if (!column) {
diff --git a/packages/nocodb/src/services/v3/tables-v3.service.ts b/packages/nocodb/src/services/v3/tables-v3.service.ts
index c4044c43b1..69d0aeb24e 100644
--- a/packages/nocodb/src/services/v3/tables-v3.service.ts
+++ b/packages/nocodb/src/services/v3/tables-v3.service.ts
@@ -153,6 +153,14 @@ export class TablesV3Service {
true,
context,
);
+ for (const field of param.table.fields ?? []) {
+ validatePayload(
+ `swagger-v3.json#/components/schemas/FieldOptions/${field.type}`,
+ field,
+ true,
+ context,
+ );
+ }
const tableCreateReq: any = param.table;
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.ts
index bd657f0891..6f17d88409 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
@@ -129,7 +129,9 @@ export default function () {
.send({ title: 'AnotherColumn' })
.expect(400);
expect(result.body.error).to.eq('INVALID_REQUEST_BODY');
- expect(result.body.message).to.include('Invalid request body');
+ expect(result.body.message).to.satisfy((msg) =>
+ msg.startsWith('Duplicate column alias'),
+ );
});
it('will handle incorrect title length', async () => {
const longTitle = 'a'.repeat(300);
@@ -139,7 +141,9 @@ export default function () {
.send({ title: longTitle })
.expect(400);
expect(result.body.error).to.eq('INVALID_REQUEST_BODY');
- expect(result.body.message).to.include('Invalid request body');
+ expect(result.body.message).to.satisfy((msg) =>
+ msg.startsWith('Column title aaaaa'),
+ );
});
it('will handle uidt incorrect', async () => {
const result = await request(context.app)
@@ -158,8 +162,8 @@ export default function () {
.delete(`${API_PREFIX}/fields/NOT_FOUND`)
.set('xc-token', context.xc_token)
.expect(422);
- expect(result.body.error).to.eq('COLUMN_NOT_FOUND');
- expect(result.body.message).to.include(`Column 'NOT_FOUND' not found`);
+ expect(result.body.error).to.eq('FIELD_NOT_FOUND');
+ expect(result.body.message).to.include(`Field 'NOT_FOUND' not found`);
});
});
});
diff --git a/packages/nocodb/tests/unit/rest/tests/metaApiV3/error-handling/table.test.ts b/packages/nocodb/tests/unit/rest/tests/metaApiV3/error-handling/table.test.ts
index 1c14a85abd..f617beb13b 100644
--- a/packages/nocodb/tests/unit/rest/tests/metaApiV3/error-handling/table.test.ts
+++ b/packages/nocodb/tests/unit/rest/tests/metaApiV3/error-handling/table.test.ts
@@ -116,6 +116,30 @@ export default function () {
],
};
+ const response = await request(context.app)
+ .post(`${API_PREFIX}/tables`)
+ .set('xc-auth', context.token)
+ .send(table)
+ .expect(400);
+ console.log(response.body)
+ expect(response.body.error).to.eq('INVALID_REQUEST_BODY');
+ });
+
+ it(`will create column with incorrect type`, async () => {
+ const table = {
+ title: 'Table Number',
+ description: 'Description',
+ fields: [
+ {
+ title: 'Number',
+ type: 'Numbers',
+ options: {
+ thousand_separator: true,
+ },
+ },
+ ],
+ };
+
const response = await request(context.app)
.post(`${API_PREFIX}/tables`)
.set('xc-auth', context.token)