Browse Source

refactor: add ids object array and validate and generate where condition

pull/6748/head
Pranav C 1 year ago
parent
commit
184bd512fe
  1. 4
      packages/nocodb/src/controllers/data-table.controller.ts
  2. 18
      packages/nocodb/src/db/BaseModelSqlv2.ts
  3. 4
      packages/nocodb/src/services/data-table.service.ts

4
packages/nocodb/src/controllers/data-table.controller.ts

@ -151,7 +151,7 @@ export class DataTableController {
@Query('viewId') viewId: string,
@Param('columnId') columnId: string,
@Param('rowId') rowId: string,
@Body() refRowIds: string | string[] | number | number[],
@Body() refRowIds: string | string[] | number | number[] | Record<string, any>,
) {
return await this.dataTableService.nestedLink({
modelId,
@ -172,7 +172,7 @@ export class DataTableController {
@Query('viewId') viewId: string,
@Param('columnId') columnId: string,
@Param('rowId') rowId: string,
@Body() refRowIds: string | string[] | number | number[],
@Body() refRowIds: string | string[] | number | number[] | Record<string, any>,
) {
return await this.dataTableService.nestedUnlink({
modelId,

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

@ -4332,7 +4332,7 @@ class BaseModelSqlv2 {
rowId,
}: {
cookie: any;
childIds: (string | number)[];
childIds: (string | number | Record<string, any>)[];
colId: string;
rowId: string;
}) {
@ -4973,13 +4973,27 @@ function applyPaginate(
}
export function _wherePk(primaryKeys: Column[], id: unknown | unknown[]) {
const where = {};
// if id object is provided use as it is
if (id && typeof id === 'object') {
// verify all pk columns are present in id object
for (const pk of primaryKeys) {
if (pk.title in id) {
where[pk.column_name] = id[pk.title];
} else if (pk.column_name in id) {
where[pk.column_name] = id[pk.column_name];
} else {
NcError.badRequest(
`Primary key column ${pk.title} not found in id object`,
);
}
}
return id;
}
const ids = Array.isArray(id) ? id : (id + '').split('___');
const where = {};
for (let i = 0; i < primaryKeys.length; ++i) {
if (primaryKeys[i].dt === 'bytea') {
// if column is bytea, then we need to encode the id to hex based on format

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

@ -368,7 +368,7 @@ export class DataTableService {
modelId: string;
columnId: string;
query: any;
refRowIds: string | string[] | number | number[];
refRowIds: string | string[] | number | number[]| Record<string, any>;
rowId: string;
}) {
this.validateIds(param.refRowIds);
@ -403,7 +403,7 @@ export class DataTableService {
modelId: string;
columnId: string;
query: any;
refRowIds: string | string[] | number | number[];
refRowIds: string | string[] | number | number[]| Record<string, any>;
rowId: string;
}) {
this.validateIds(param.refRowIds);

Loading…
Cancel
Save