diff --git a/packages/itmat-apis/src/trpc/dataProcedure.ts b/packages/itmat-apis/src/trpc/dataProcedure.ts index 00845affe..c059ebe07 100644 --- a/packages/itmat-apis/src/trpc/dataProcedure.ts +++ b/packages/itmat-apis/src/trpc/dataProcedure.ts @@ -198,7 +198,7 @@ export class DataRouter { fieldIds: z.optional(z.array(z.string())), useCache: z.optional(z.boolean()), forceUpdate: z.optional(z.boolean()), - formatted: z.optional(z.string()) + fromCold: z.optional(z.boolean()) })).query(async (opts) => { return await this.dataCore.getData( opts.ctx.req.user, @@ -207,7 +207,8 @@ export class DataRouter { opts.input.versionId, opts.input.aggregation, opts.input.useCache, - opts.input.forceUpdate + opts.input.forceUpdate, + opts.input.fromCold ); }), /** diff --git a/packages/itmat-cores/src/coreFunc/dataCore.ts b/packages/itmat-cores/src/coreFunc/dataCore.ts index cea83b8cd..c8e8c6d8c 100644 --- a/packages/itmat-cores/src/coreFunc/dataCore.ts +++ b/packages/itmat-cores/src/coreFunc/dataCore.ts @@ -748,7 +748,7 @@ export class DataCore { * * @return Partial[] - The list of objects of Partial */ - public async getData(requester: IUserWithoutToken | undefined, studyId: string, selectedFieldIds?: string[], dataVersion?: string | null | Array, aggregation?: Record }>>, useCache?: boolean, forceUpdate?: boolean) { + public async getData(requester: IUserWithoutToken | undefined, studyId: string, selectedFieldIds?: string[], dataVersion?: string | null | Array, aggregation?: Record }>>, useCache?: boolean, forceUpdate?: boolean, fromCold?: boolean) { if (!requester) { throw new CoreError( enumCoreErrors.NOT_LOGGED_IN, @@ -811,7 +811,7 @@ export class DataCore { return await getJsonFileContents(this.objStore, 'cache', hashedInfo[0].uri); } else { // raw data by the permission - const data = await this.getDataByRoles(requester, roles, studyId, availableDataVersions, fieldIds); + const data = await this.getDataByRoles(requester, roles, studyId, availableDataVersions, fieldIds, fromCold); // data transformation if aggregation is provided const transformed = aggregation ? this.dataTransformationCore.transformationAggregate(data as unknown as IDataTransformationClipArray, aggregation) : data; // write to minio and cache collection @@ -843,7 +843,7 @@ export class DataCore { } } else { // raw data by the permission - const data = await this.getDataByRoles(requester, roles, studyId, availableDataVersions, fieldIds); + const data = await this.getDataByRoles(requester, roles, studyId, availableDataVersions, fieldIds, fromCold); // data transformation if aggregation is provided const transformed = aggregation ? this.dataTransformationCore.transformationAggregate(data as unknown as IDataTransformationClipArray, aggregation) : data; return transformed; @@ -1275,12 +1275,14 @@ export class DataCore { } - public async getDataByRoles(requester: IUserWithoutToken, roles: IRole[], studyId: string, dataVersions: Array, fieldIds?: string[]) { + public async getDataByRoles(requester: IUserWithoutToken, roles: IRole[], studyId: string, dataVersions: Array, fieldIds?: string[], fromCold?: boolean) { const matchFilter: Filter = { studyId: studyId, dataVersion: { $in: dataVersions } }; + const dbCollection = fromCold ? this.db.collections.colddata_collection : this.db.collections.data_collection; + const roleArr: Filter[] = []; for (const role of roles) { const permissionArr: Filter[] = []; @@ -1316,12 +1318,15 @@ export class DataCore { const queryField = async (fieldId: string) => { if (availableFieldIds.includes(fieldId) || availableFieldIds.some(el => new RegExp(el).test(fieldId))) { const propertyFilter: Record = {}; + if (!availableFields[fieldId]) { + return []; + } if (availableFields[fieldId].properties) { for (const property of availableFields[fieldId].properties) { propertyFilter[`${property.name}`] = `$properties.${property.name}`; } } - const data = await this.db.collections.data_collection.aggregate([{ + const data = await dbCollection.aggregate([{ $match: { ...matchFilter, fieldId: fieldId, diff --git a/packages/itmat-types/src/types/file.ts b/packages/itmat-types/src/types/file.ts index 1a0753dcf..5ff4ea17b 100644 --- a/packages/itmat-types/src/types/file.ts +++ b/packages/itmat-types/src/types/file.ts @@ -29,6 +29,7 @@ export enum enumFileTypes { DOCX = 'DOCX', XLSX = 'XLSX', XLS = 'XLS', + MAT = 'MAT', // images JPG = 'JPG', JPEG = 'JPEG',