Browse Source

fix(nocodb): type errors

pull/5222/head
Wing-Kam Wong 2 years ago
parent
commit
b507a1def3
  1. 4
      packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/genRollupSelectv2.ts
  2. 19
      packages/nocodb/src/lib/models/RollupColumn.ts
  3. 5
      packages/nocodb/src/lib/version-upgrader/ncProjectUpgraderV2_0090000.ts

4
packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/genRollupSelectv2.ts

@ -29,7 +29,7 @@ export default async function ({
case RelationTypes.HAS_MANY: case RelationTypes.HAS_MANY:
return { return {
builder: knex(`${childModel?.table_name} as ${refTableAlias}`) builder: knex(`${childModel?.table_name} as ${refTableAlias}`)
[columnOptions.rollup_function]?.( [columnOptions.rollup_function as string]?.(
knex.ref(`${refTableAlias}.${rollupColumn.column_name}`) knex.ref(`${refTableAlias}.${rollupColumn.column_name}`)
) )
.where( .where(
@ -47,7 +47,7 @@ export default async function ({
return { return {
builder: knex(`${parentModel?.table_name} as ${refTableAlias}`) builder: knex(`${parentModel?.table_name} as ${refTableAlias}`)
[columnOptions.rollup_function]?.( [columnOptions.rollup_function as string]?.(
knex.ref(`${refTableAlias}.${rollupColumn.column_name}`) knex.ref(`${refTableAlias}.${rollupColumn.column_name}`)
) )
.innerJoin( .innerJoin(

19
packages/nocodb/src/lib/models/RollupColumn.ts

@ -5,19 +5,22 @@ import NocoCache from '../cache/NocoCache';
import { extractProps } from '../meta/helpers/extractProps'; import { extractProps } from '../meta/helpers/extractProps';
import type { RollupType } from 'nocodb-sdk'; import type { RollupType } from 'nocodb-sdk';
export const ROLLUP_FUNCTIONS = <const>[
'count',
'min',
'max',
'avg',
'countDistinct',
'sumDistinct',
'avgDistinct',
];
export default class RollupColumn implements RollupType { export default class RollupColumn implements RollupType {
id: string; id: string;
fk_column_id; fk_column_id;
fk_relation_column_id; fk_relation_column_id;
fk_rollup_column_id; fk_rollup_column_id;
rollup_function: rollup_function: typeof ROLLUP_FUNCTIONS[number];
| 'count'
| 'min'
| 'max'
| 'avg'
| 'countDistinct'
| 'sumDistinct'
| 'avgDistinct';
constructor(data: Partial<RollupColumn>) { constructor(data: Partial<RollupColumn>) {
Object.assign(this, data); Object.assign(this, data);

5
packages/nocodb/src/lib/version-upgrader/ncProjectUpgraderV2_0090000.ts

@ -14,7 +14,7 @@ import {
import Column from '../models/Column'; import Column from '../models/Column';
import LinkToAnotherRecordColumn from '../models/LinkToAnotherRecordColumn'; import LinkToAnotherRecordColumn from '../models/LinkToAnotherRecordColumn';
import NcHelp from '../utils/NcHelp'; import NcHelp from '../utils/NcHelp';
import RollupColumn from '../models/RollupColumn'; import RollupColumn, { ROLLUP_FUNCTIONS } from '../models/RollupColumn';
import View from '../models/View'; import View from '../models/View';
import GridView from '../models/GridView'; import GridView from '../models/GridView';
import KanbanView from '../models/KanbanView'; import KanbanView from '../models/KanbanView';
@ -613,7 +613,8 @@ async function migrateProjectModels(
const colBody: Partial<RollupColumn & Column> = { const colBody: Partial<RollupColumn & Column> = {
title: columnMeta._cn, title: columnMeta._cn,
rollup_function: columnMeta.rl.fn, rollup_function: columnMeta.rl
.fn as typeof ROLLUP_FUNCTIONS[number],
}; };
colBody.fk_rollup_column_id = colBody.fk_rollup_column_id =

Loading…
Cancel
Save