Browse Source

fix: error code corrections

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/5747/head
Pranav C 1 year ago
parent
commit
73f83a8815
  1. 8
      packages/nocodb/src/db/BaseModelSqlv2.ts
  2. 27
      packages/nocodb/src/services/data-table.service.ts
  3. 2
      packages/nocodb/tests/unit/rest/tests/newDataApis.test.ts

8
packages/nocodb/src/db/BaseModelSqlv2.ts

@ -3628,7 +3628,7 @@ class BaseModelSqlv2 {
const column = columns.find((c) => c.id === colId);
if (!column || column.uidt !== UITypes.LinkToAnotherRecord)
NcError.notFound(`Link column with id ${colId} not found`);
NcError.notFound(`Link column ${colId} not found`);
const row = await this.dbDriver(this.tnPath)
.where(await this._wherePk(rowId))
@ -3636,7 +3636,7 @@ class BaseModelSqlv2 {
// validate rowId
if (!row) {
NcError.notFound(`Row with id ${rowId} not found`);
NcError.notFound(`Row '${rowId}' not found`);
}
const colOptions = await column.getColOptions<LinkToAnotherRecordColumn>();
@ -3851,7 +3851,7 @@ class BaseModelSqlv2 {
const column = columns.find((c) => c.id === colId);
if (!column || column.uidt !== UITypes.LinkToAnotherRecord)
NcError.notFound(`Link column with id ${colId} not found`);
NcError.notFound(`Link column ${colId} not found`);
const row = await this.dbDriver(this.tnPath)
.where(await this._wherePk(rowId))
@ -3859,7 +3859,7 @@ class BaseModelSqlv2 {
// validate rowId
if (!row) {
NcError.notFound(`Row with id ${rowId} not found`);
NcError.notFound(`Row '${rowId}' not found`);
}
const colOptions = await column.getColOptions<LinkToAnotherRecordColumn>();

27
packages/nocodb/src/services/data-table.service.ts

@ -168,11 +168,11 @@ export class DataTableService {
const model = await Model.get(param.modelId);
if (!model) {
NcError.notFound(`Table with id '${param.modelId}' not found`);
NcError.notFound(`Table '${param.modelId}' not found`);
}
if (param.projectId && model.project_id !== param.projectId) {
throw new Error('Model not belong to project');
throw new Error('Table not belong to project');
}
let view: View;
@ -180,7 +180,7 @@ export class DataTableService {
if (param.viewId) {
view = await View.get(param.viewId);
if (!view || (view.fk_model_id && view.fk_model_id !== param.modelId)) {
NcError.unprocessableEntity(`View with id '${param.viewId}' not found`);
NcError.unprocessableEntity(`View '${param.viewId}' not found`);
}
}
@ -252,6 +252,11 @@ export class DataTableService {
viewId: view?.id,
dbDriver: await NcConnectionMgrv2.get(base),
});
if (!(await baseModel.exist(param.rowId))) {
NcError.notFound(`Row '${param.rowId}' not found`);
}
const column = await this.getColumn(param);
const colOptions = await column.getColOptions<LinkToAnotherRecordColumn>();
@ -321,7 +326,7 @@ export class DataTableService {
private async getColumn(param: { modelId: string; columnId: string }) {
const column = await Column.get({ colId: param.columnId });
if (!column) NcError.badRequest(`Column with id '${param.columnId}' not found`);
if (!column) NcError.notFound(`Column '${param.columnId}' not found`);
if (column.fk_model_id !== param.modelId)
NcError.badRequest('Column not belong to model');
@ -378,7 +383,8 @@ export class DataTableService {
this.validateIds(param.refRowIds);
const { model, view } = await this.getModelAndView(param);
if (!model) NcError.notFound('Table with id ' + param.modelId + ' not found');
if (!model)
NcError.notFound('Table with id ' + param.modelId + ' not found');
const base = await Base.get(model.base_id);
@ -405,14 +411,21 @@ export class DataTableService {
private validateIds(rowIds: any[] | any) {
if (Array.isArray(rowIds)) {
const map = new Map<string, boolean>();
const set = new Set<string>();
for (const rowId of rowIds) {
if (rowId === undefined || rowId === null)
NcError.unprocessableEntity('Invalid row id ' + rowId);
if (map.has(rowId)) {
NcError.unprocessableEntity('Duplicate row with id ' + rowId);
set.add(rowId);
} else {
map.set(rowId, true);
}
map.set(rowId, true);
}
if (set.size > 0)
NcError.unprocessableEntity(
'Child record with id [' + [...set].join(', ') + '] are duplicated',
);
} else if (rowIds === undefined || rowIds === null) {
NcError.unprocessableEntity('Invalid row id ' + rowIds);
}

2
packages/nocodb/tests/unit/rest/tests/newDataApis.test.ts

@ -2409,7 +2409,7 @@ function linkBased() {
...validParams,
body: [1, 2, 1, 2],
status: 422,
msg: 'Child record with id [1, 2] contains duplicate value',
msg: 'Child record with id [1, 2] are duplicated',
});
}
}

Loading…
Cancel
Save