Browse Source

refactor: error code corrections

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/5747/head
Pranav C 1 year ago
parent
commit
18273caade
  1. 32
      packages/nocodb/src/db/BaseModelSqlv2.ts
  2. 10
      packages/nocodb/src/services/data-table.service.ts

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

@ -17,8 +17,8 @@ import Validator from 'validator';
import { customAlphabet } from 'nanoid';
import DOMPurify from 'isomorphic-dompurify';
import { v4 as uuidv4 } from 'uuid';
import { extractLimitAndOffset } from '../helpers';
import { Knex } from 'knex';
import { extractLimitAndOffset } from '../helpers';
import { NcError } from '../helpers/catchError';
import getAst from '../helpers/getAst';
import {
@ -3628,7 +3628,7 @@ class BaseModelSqlv2 {
const column = columns.find((c) => c.id === colId);
if (!column || column.uidt !== UITypes.LinkToAnotherRecord)
NcError.notFound('Column not found');
NcError.notFound(`Link column with id ${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 not found');
NcError.notFound(`Row with id ${rowId} not found`);
}
const colOptions = await column.getColOptions<LinkToAnotherRecordColumn>();
@ -3809,7 +3809,9 @@ class BaseModelSqlv2 {
const childRow = await childRowsQb;
if (!childRow) {
NcError.unprocessableEntity(`Child record with id ${childIds[0]} not found`);
NcError.unprocessableEntity(
`Child record with id ${childIds[0]} not found`,
);
}
}
@ -3849,7 +3851,7 @@ class BaseModelSqlv2 {
const column = columns.find((c) => c.id === colId);
if (!column || column.uidt !== UITypes.LinkToAnotherRecord)
NcError.notFound('Column not found');
NcError.notFound(`Link column with id ${colId} not found`);
const row = await this.dbDriver(this.tnPath)
.where(await this._wherePk(rowId))
@ -3857,7 +3859,7 @@ class BaseModelSqlv2 {
// validate rowId
if (!row) {
NcError.notFound('Row not found');
NcError.notFound(`Row with id ${rowId} not found`);
}
const colOptions = await column.getColOptions<LinkToAnotherRecordColumn>();
@ -3961,6 +3963,11 @@ class BaseModelSqlv2 {
{
// validate Ids
{
if (childIds.length > 1)
NcError.unprocessableEntity(
'Request must contain only one parent id',
);
const childRowsQb = this.dbDriver(parentTn)
.select(parentTable.primaryKey.column_name)
.where(_wherePk(parentTable.primaryKeys, childIds[0]))
@ -3969,7 +3976,9 @@ class BaseModelSqlv2 {
const childRow = await childRowsQb;
if (!childRow) {
NcError.unprocessableEntity(`Child record with id ${childIds[0]} not found`);
NcError.unprocessableEntity(
`Child record with id ${childIds[0]} not found`,
);
}
}
@ -4004,6 +4013,15 @@ class BaseModelSqlv2 {
(c) => c.id === colId,
);
const row = await this.dbDriver(this.tnPath)
.where(await this._wherePk(id))
.first();
// validate rowId
if (!row) {
NcError.notFound(`Row with id ${id} not found`);
}
const parentCol = await (
(await relColumn.getColOptions()) as LinkToAnotherRecordColumn
).getParentColumn();

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

@ -6,7 +6,6 @@ import getAst from '../helpers/getAst';
import { PagedResponseImpl } from '../helpers/PagedResponse';
import { Base, Column, Model, View } from '../models';
import NcConnectionMgrv2 from '../utils/common/NcConnectionMgrv2';
import { referencedRowIdParam } from './api-docs/swagger/templates/params';
import { DatasService } from './datas.service';
import type { LinkToAnotherRecordColumn } from '../models';
@ -169,7 +168,7 @@ export class DataTableService {
const model = await Model.get(param.modelId);
if (!model) {
NcError.notFound(`Table '${param.modelId}' not found`);
NcError.notFound(`Table with id '${param.modelId}' not found`);
}
if (param.projectId && model.project_id !== param.projectId) {
@ -181,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 '${param.viewId}' not found`);
NcError.unprocessableEntity(`View with id '${param.viewId}' not found`);
}
}
@ -322,7 +321,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 not found');
if (!column) NcError.badRequest(`Column with id '${param.columnId}' not found`);
if (column.fk_model_id !== param.modelId)
NcError.badRequest('Column not belong to model');
@ -344,7 +343,6 @@ export class DataTableService {
this.validateIds(param.refRowIds);
const { model, view } = await this.getModelAndView(param);
if (!model) NcError.notFound('Table not found');
const base = await Base.get(model.base_id);
@ -380,7 +378,7 @@ export class DataTableService {
this.validateIds(param.refRowIds);
const { model, view } = await this.getModelAndView(param);
if (!model) NcError.notFound('Table not found');
if (!model) NcError.notFound('Table with id ' + param.modelId + ' not found');
const base = await Base.get(model.base_id);

Loading…
Cancel
Save