Browse Source

fix(nc-gui): skip pagination for data-opts service

pull/7716/head
DarkPhoenix2704 8 months ago
parent
commit
63c5ec46e7
  1. 59
      packages/nocodb/src/services/calendar-datas.service.ts
  2. 66
      packages/nocodb/src/services/datas.service.ts

59
packages/nocodb/src/services/calendar-datas.service.ts

@ -1,13 +1,9 @@
import { Injectable, Logger } from '@nestjs/common';
import { ErrorMessages, ViewTypes } from 'nocodb-sdk';
import { nocoExecute } from 'nc-help';
import dayjs from 'dayjs';
import type { CalendarRangeType, FilterType } from 'nocodb-sdk';
import { CalendarRange, Model, Source, View } from '~/models';
import { NcBaseError, NcError } from '~/helpers/catchError';
import getAst from '~/helpers/getAst';
import { PagedResponseImpl } from '~/helpers/PagedResponse';
import NcConnectionMgrv2 from '~/utils/common/NcConnectionMgrv2';
import { CalendarRange, Model, View } from '~/models';
import { NcError } from '~/helpers/catchError';
import { DatasService } from '~/services/datas.service';
@Injectable()
@ -47,54 +43,11 @@ export class CalendarDatasService {
id: view.fk_model_id,
});
const source = await Source.get(model.source_id);
const baseModel = await Model.getBaseModelSQL({
id: model.id,
viewId: view?.id,
dbDriver: await NcConnectionMgrv2.get(source),
});
const { ast, dependencyFields } = await getAst({
model,
query,
view,
});
const listArgs: any = dependencyFields;
try {
listArgs.filterArr = JSON.parse(listArgs.filterArrJson);
} catch (e) {}
try {
listArgs.sortArr = JSON.parse(listArgs.sortArrJson);
} catch (e) {}
const [count, data] = await Promise.all([
baseModel.count(listArgs, false),
(async () => {
let data = [];
try {
data = await nocoExecute(
ast,
await baseModel.list(listArgs, {
ignoreViewFilterAndSort: false,
}),
{},
listArgs,
);
} catch (e) {
if (e instanceof NcBaseError) throw e;
this.logger.error(e);
NcError.internalServerError(
'Please check server log for more details',
);
}
return data;
})(),
]);
return new PagedResponseImpl(data, {
return await this.datasService.dataList({
...param,
...query,
count,
baseName: model.base_id,
tableName: model.id,
});
}

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

@ -1,13 +1,12 @@
import { Injectable, Logger } from '@nestjs/common';
import { isSystemColumn, ViewTypes } from 'nocodb-sdk';
import { isSystemColumn } from 'nocodb-sdk';
import * as XLSX from 'xlsx';
import papaparse from 'papaparse';
import { nocoExecute } from 'nc-help';
import dayjs from 'dayjs';
import type { BaseModelSqlv2 } from '~/db/BaseModelSqlv2';
import type { PathParams } from '~/modules/datas/helpers';
import { getDbRows, getViewAndModelByAliasOrId } from '~/modules/datas/helpers';
import { Base, CalendarRange, Column, Model, Source, View } from '~/models';
import { Base, Column, Model, Source, View } from '~/models';
import { NcBaseError, NcError } from '~/helpers/catchError';
import getAst from '~/helpers/getAst';
import { PagedResponseImpl } from '~/helpers/PagedResponse';
@ -211,67 +210,6 @@ export class DatasService {
});
}
async getCalendarRecordCount(param: { viewId: string; query: any }) {
const { viewId, query = {} } = param;
const view = await View.get(viewId);
if (!view) NcError.notFound('View not found');
if (view.type !== ViewTypes.CALENDAR)
NcError.badRequest('View is not a calendar view');
const calendarRange = await CalendarRange.read(view.id);
if (!calendarRange?.ranges?.length) NcError.badRequest('No ranges found');
const model = await Model.getByIdOrName({
id: view.fk_model_id,
});
const data = await this.getDataList({
model,
view,
query,
});
if (!data) NcError.notFound('Data not found');
const dates: Array<string> = [];
calendarRange.ranges.forEach((range: any) => {
data.list.forEach((date) => {
const from =
date[
model.columns.find((c) => c.id === range.fk_from_column_id).title
];
let to;
if (range.fk_to_column_id) {
to =
date[
model.columns.find((c) => c.id === range.fk_to_column_id).title
];
}
if (from && to) {
const fromDt = dayjs(from);
const toDt = dayjs(to);
let current = fromDt;
while (current.isSameOrBefore(toDt)) {
dates.push(current.format('YYYY-MM-DD HH:mm:ssZ'));
current = current.add(1, 'day');
}
} else if (from) {
dates.push(dayjs(from).format('YYYY-MM-DD HH:mm:ssZ'));
}
});
});
return dates;
}
async getFindOne(param: { model: Model; view: View; query: any }) {
const { model, view, query = {} } = param;

Loading…
Cancel
Save