Browse Source

fix(nocodb): refactor models and services

pull/7611/head
DarkPhoenix2704 9 months ago
parent
commit
bf67a12956
  1. 2
      packages/nocodb/src/helpers/getAst.ts
  2. 38
      packages/nocodb/src/models/CalendarRange.ts
  3. 28
      packages/nocodb/src/models/View.ts
  4. 2
      packages/nocodb/src/modules/jobs/jobs/export-import/import.service.ts
  5. 4
      packages/nocodb/src/schema/swagger.json
  6. 2
      packages/nocodb/src/services/datas.service.ts
  7. 2
      packages/nocodb/src/services/public-datas.service.ts

2
packages/nocodb/src/helpers/getAst.ts

@ -60,7 +60,7 @@ const getAst = async ({
if (calenderRanges) {
dependencyFieldsForCalenderView = calenderRanges.ranges
.flatMap((obj) =>
[obj.fk_from_column_id, obj.fk_to_column_id].filter(Boolean),
[obj.fk_from_column_id, (obj as any).fk_to_column_id].filter(Boolean),
)
.map(String);
}

38
packages/nocodb/src/models/CalendarRange.ts

@ -7,7 +7,6 @@ import { CacheDelDirection, CacheScope, MetaTable } from '~/utils/globals';
export default class CalendarRange implements CalendarRangeType {
id?: string;
fk_from_column_id?: string;
fk_to_column_id?: string | null;
fk_view_id?: string;
constructor(data: Partial<CalendarRange>) {
@ -18,43 +17,39 @@ export default class CalendarRange implements CalendarRangeType {
data: Partial<CalendarRange>[],
ncMeta = Noco.ncMeta,
) {
const insertObj = [];
let insertObj = [];
for (const d of data) {
const tempObj = extractProps(d, [
'fk_from_column_id',
'fk_to_column_id',
'fk_view_id',
]);
const tempObj = extractProps(d, ['fk_from_column_id', 'fk_view_id']);
insertObj.push(tempObj);
}
const bulkData = await ncMeta.bulkMetaInsert(
if (!insertObj.length) return false;
insertObj = insertObj[0];
const insertData = await ncMeta.metaInsert2(
null,
null,
MetaTable.CALENDAR_VIEW_RANGE,
insertObj,
);
const uniqueFks: string[] = [
...new Set(bulkData.map((d) => d.fk_view_id)),
] as string[];
for (const fk of uniqueFks) {
await NocoCache.deepDel(
`${CacheScope.CALENDAR_VIEW_RANGE}:${fk}:list`,
`${CacheScope.CALENDAR_VIEW_RANGE}:${insertData.fk_view_id}:list`,
CacheDelDirection.PARENT_TO_CHILD,
);
}
for (const d of bulkData) {
await NocoCache.set(`${CacheScope.CALENDAR_VIEW_RANGE}:${d.id}`, d);
await NocoCache.set(
`${CacheScope.CALENDAR_VIEW_RANGE}:${insertData.id}`,
insertData,
);
await NocoCache.appendToList(
CacheScope.CALENDAR_VIEW_RANGE,
[d.fk_view_id],
`${CacheScope.CALENDAR_VIEW_RANGE}:${d.id}`,
[insertData.fk_view_id],
`${CacheScope.CALENDAR_VIEW_RANGE}:${insertData.id}`,
);
}
return true;
}
@ -118,11 +113,6 @@ export default class CalendarRange implements CalendarRangeType {
eq: columnId,
},
},
{
fk_to_column_id: {
eq: columnId,
},
},
],
},
})

28
packages/nocodb/src/models/View.ts

@ -394,16 +394,7 @@ export default class View implements ViewType {
let calendarRanges: Array<string> | null = null;
if (view.type === ViewTypes.CALENDAR) {
const calRange = await CalendarRange.read(view_id, ncMeta);
if (calRange) {
const calIds: Set<string> = new Set();
calRange.ranges.forEach((range) => {
calIds.add(range.fk_from_column_id);
if (!range.fk_to_column_id) return;
calIds.add(range.fk_to_column_id);
});
calendarRanges = Array.from(calIds) as Array<string>;
}
calendarRanges = await View.getRangeColumnsAsArray(view_id, ncMeta);
}
if (view.type === ViewTypes.KANBAN && !copyFromView) {
@ -517,6 +508,18 @@ export default class View implements ViewType {
});
}
static async getRangeColumnsAsArray(viewId: string, ncMeta) {
const calRange = await CalendarRange.read(viewId, ncMeta);
if (calRange) {
const calIds: Set<string> = new Set();
calRange.ranges.forEach((range) => {
calIds.add(range.fk_from_column_id);
});
return Array.from(calIds) as Array<string>;
}
return [];
}
static async insertColumnToAllViews(
param: {
fk_column_id: any;
@ -1639,7 +1642,10 @@ export default class View implements ViewType {
const calendarRange = await CalendarRange.read(view.id, ncMeta);
if (!calendarRange) break;
const calendarRangeColumns = calendarRange.ranges
.map((range) => [range.fk_from_column_id, range.fk_to_column_id])
.map((range) => [
range.fk_from_column_id,
(range as any).fk_to_column_id,
])
.flat();
if (calendarRangeColumns.includes(column.id)) {

2
packages/nocodb/src/modules/jobs/jobs/export-import/import.service.ts

@ -1229,7 +1229,7 @@ export class ImportService {
calendar_range: (vw.view as CalendarView).calendar_range.map(
(a) => ({
fk_from_column_id: idMap.get(a.fk_from_column_id),
fk_to_column_id: idMap.get(a.fk_to_column_id),
fk_to_column_id: idMap.get((a as any).fk_to_column_id),
}),
),
} as ViewCreateReqType,

4
packages/nocodb/src/schema/swagger.json

@ -20640,10 +20640,6 @@
"$ref": "#/components/schemas/Id",
"description": "Foreign Key to Column"
},
"fk_to_column_id": {
"$ref": "#/components/schemas/StringOrNull",
"description": "Foreign Key to Column"
},
"fk_view_id": {
"$ref": "#/components/schemas/StringOrNull",
"x-stoplight": {

2
packages/nocodb/src/services/datas.service.ts

@ -239,7 +239,7 @@ export class DatasService {
const dates: Array<string> = [];
ranges.forEach((range) => {
ranges.forEach((range: any) => {
data.list.forEach((date) => {
const from =
date[

2
packages/nocodb/src/services/public-datas.service.ts

@ -134,7 +134,7 @@ export class PublicDatasService {
const dates: Array<string> = [];
ranges.forEach((range) => {
ranges.forEach((range: any) => {
data.list.forEach((date) => {
const from =
date[columns.find((c) => c.id === range.fk_from_column_id).title];

Loading…
Cancel
Save