Browse Source

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

pull/7304/head
Pranav C 10 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 generateLookupSelectQuery from '~/db/generateLookupSelectQuery';
import { getAliasGenerator } from '~/utils';
import {getRefColumnIfAlias} from "~/helpers";
// tod: tobe fixed
// extend(customParseFormat);
@ -128,7 +129,8 @@ const parseConditionV2 = async (
(filter.comparison_op as any) === 'gb_eq' ||
(filter.comparison_op as any) === 'gb_null'
) {
const column = await filter.getColumn();
const column = await getRefColumnIfAlias(await filter.getColumn());
if (
column.uidt === UITypes.Lookup ||
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 (throwErrorIfInvalid) {
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 { Base, BaseUser, Sort } from '~/models';
import generateLookupSelectQuery from '~/db/generateLookupSelectQuery';
import {getRefColumnIfAlias} from "~/helpers";
export default async function sortV2(
baseModelSqlv2: BaseModelSqlv2,
@ -29,7 +30,7 @@ export default async function sortV2(
} else {
sort = new Sort(_sort);
}
const column = await sort.getColumn();
const column = await getRefColumnIfAlias(await sort.getColumn());
if (!column) {
if (throwErrorIfInvalid) {
NcError.unprocessableEntity(`Invalid field: ${sort.fk_column_id}`);

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

@ -1,7 +1,6 @@
import { customAlphabet } from 'nanoid';
import { getAvailableRollupForUiType, UITypes } from 'nocodb-sdk';
import { pluralize, singularize } from 'inflection';
import type { RollupColumn } from '~/models';
import type {
BoolType,
ColumnReqType,
@ -11,13 +10,14 @@ import type {
RollupColumnReqType,
TableType,
} from 'nocodb-sdk';
import type { RollupColumn } from '~/models';
import type LinkToAnotherRecordColumn from '~/models/LinkToAnotherRecordColumn';
import type LookupColumn from '~/models/LookupColumn';
import type Model from '~/models/Model';
import { GridViewColumn } from '~/models';
import validateParams from '~/helpers/validateParams';
import { getUniqueColumnAliasName } from '~/helpers/getUniqueName';
import Column from '~/models/Column';
import { GridViewColumn } from '~/models';
export const randomID = customAlphabet(
'1234567890abcdefghijklmnopqrstuvwxyz_',
@ -287,3 +287,16 @@ export const sanitizeColumnName = (name: string) => {
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