Browse Source

fix: get system column when using created/lastmodified in filter or sort

pull/7304/head
Pranav C 11 months ago
parent
commit
0361122875
  1. 6
      packages/nocodb/src/db/conditionV2.ts
  2. 3
      packages/nocodb/src/db/sortV2.ts
  3. 17
      packages/nocodb/src/helpers/columnHelpers.ts

6
packages/nocodb/src/db/conditionV2.ts

@ -21,6 +21,7 @@ import { sanitize } from '~/helpers/sqlSanitize';
import Filter from '~/models/Filter'; import Filter from '~/models/Filter';
import generateLookupSelectQuery from '~/db/generateLookupSelectQuery'; import generateLookupSelectQuery from '~/db/generateLookupSelectQuery';
import { getAliasGenerator } from '~/utils'; import { getAliasGenerator } from '~/utils';
import {getRefColumnIfAlias} from "~/helpers";
// tod: tobe fixed // tod: tobe fixed
// extend(customParseFormat); // extend(customParseFormat);
@ -128,7 +129,8 @@ const parseConditionV2 = async (
(filter.comparison_op as any) === 'gb_eq' || (filter.comparison_op as any) === 'gb_eq' ||
(filter.comparison_op as any) === 'gb_null' (filter.comparison_op as any) === 'gb_null'
) { ) {
const column = await filter.getColumn(); const column = await getRefColumnIfAlias(await filter.getColumn());
if ( if (
column.uidt === UITypes.Lookup || column.uidt === UITypes.Lookup ||
column.uidt === UITypes.LinkToAnotherRecord column.uidt === UITypes.LinkToAnotherRecord
@ -157,7 +159,7 @@ const parseConditionV2 = async (
} }
} }
const column = await filter.getColumn(); const column = await getRefColumnIfAlias(await filter.getColumn());
if (!column) { if (!column) {
if (throwErrorIfInvalid) { if (throwErrorIfInvalid) {
NcError.unprocessableEntity(`Invalid field: ${filter.fk_column_id}`); NcError.unprocessableEntity(`Invalid field: ${filter.fk_column_id}`);

3
packages/nocodb/src/db/sortV2.ts

@ -8,6 +8,7 @@ import genRollupSelectv2 from '~/db/genRollupSelectv2';
import { sanitize } from '~/helpers/sqlSanitize'; import { sanitize } from '~/helpers/sqlSanitize';
import { Base, BaseUser, Sort } from '~/models'; import { Base, BaseUser, Sort } from '~/models';
import generateLookupSelectQuery from '~/db/generateLookupSelectQuery'; import generateLookupSelectQuery from '~/db/generateLookupSelectQuery';
import {getRefColumnIfAlias} from "~/helpers";
export default async function sortV2( export default async function sortV2(
baseModelSqlv2: BaseModelSqlv2, baseModelSqlv2: BaseModelSqlv2,
@ -29,7 +30,7 @@ export default async function sortV2(
} else { } else {
sort = new Sort(_sort); sort = new Sort(_sort);
} }
const column = await sort.getColumn(); const column = await getRefColumnIfAlias(await sort.getColumn());
if (!column) { if (!column) {
if (throwErrorIfInvalid) { if (throwErrorIfInvalid) {
NcError.unprocessableEntity(`Invalid field: ${sort.fk_column_id}`); NcError.unprocessableEntity(`Invalid field: ${sort.fk_column_id}`);

17
packages/nocodb/src/helpers/columnHelpers.ts

@ -1,7 +1,6 @@
import { customAlphabet } from 'nanoid'; import { customAlphabet } from 'nanoid';
import { getAvailableRollupForUiType, UITypes } from 'nocodb-sdk'; import { getAvailableRollupForUiType, UITypes } from 'nocodb-sdk';
import { pluralize, singularize } from 'inflection'; import { pluralize, singularize } from 'inflection';
import type { RollupColumn } from '~/models';
import type { import type {
BoolType, BoolType,
ColumnReqType, ColumnReqType,
@ -11,13 +10,14 @@ import type {
RollupColumnReqType, RollupColumnReqType,
TableType, TableType,
} from 'nocodb-sdk'; } from 'nocodb-sdk';
import type { RollupColumn } from '~/models';
import type LinkToAnotherRecordColumn from '~/models/LinkToAnotherRecordColumn'; import type LinkToAnotherRecordColumn from '~/models/LinkToAnotherRecordColumn';
import type LookupColumn from '~/models/LookupColumn'; import type LookupColumn from '~/models/LookupColumn';
import type Model from '~/models/Model'; import type Model from '~/models/Model';
import { GridViewColumn } from '~/models';
import validateParams from '~/helpers/validateParams'; import validateParams from '~/helpers/validateParams';
import { getUniqueColumnAliasName } from '~/helpers/getUniqueName'; import { getUniqueColumnAliasName } from '~/helpers/getUniqueName';
import Column from '~/models/Column'; import Column from '~/models/Column';
import { GridViewColumn } from '~/models';
export const randomID = customAlphabet( export const randomID = customAlphabet(
'1234567890abcdefghijklmnopqrstuvwxyz_', '1234567890abcdefghijklmnopqrstuvwxyz_',
@ -287,3 +287,16 @@ export const sanitizeColumnName = (name: string) => {
return columnName; return columnName;
}; };
// if column is an alias column then return the original column
// for example CreatedTime is an alias column for CreateTime system column
export const getRefColumnIfAlias = (column: Column, columns?: Column[]) => {
if (![UITypes.CreateTime, UITypes.LastModifiedTime].includes(column.uidt))
return column;
return (
(columns || (await Column.list({ fk_model_id: column.fk_model_id }))).find(
(c) => c.system && c.uidt === column.uidt,
) || column
);
};

Loading…
Cancel
Save