Skip to content

Commit

Permalink
feat: Add a getFilesLatest API to fast fetch versioned files
Browse files Browse the repository at this point in the history
  • Loading branch information
wsy19961129 committed Sep 3, 2024
1 parent 0e487c1 commit b995750
Show file tree
Hide file tree
Showing 5 changed files with 294 additions and 234 deletions.
9 changes: 7 additions & 2 deletions packages/itmat-apis/src/graphql/resolvers/fileResolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,12 @@ export class FileResolvers {
);
} else {
try {
const res = await this.dataCore.uploadFileData(context.req.user, args.studyId, await args.file, targetFieldId, args.description);
// We need to rename the properties to fit for the new V3 naming
const description = {
...parsedDescription,
subjectId: parsedDescription['participantId']
};
const res = await this.dataCore.uploadFileData(context.req.user, args.studyId, await args.file, targetFieldId, JSON.stringify(description));
const fileEntry = await this.db.collections.files_collection.findOne({ id: res.id });
if (args.fileLength) {
if (args.fileLength.toString() !== fileEntry?.fileSize.toString()) {
Expand Down Expand Up @@ -105,4 +110,4 @@ export class FileResolvers {
}
};
}
}
}
27 changes: 27 additions & 0 deletions packages/itmat-apis/src/trpc/dataProcedure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,33 @@ export class DataRouter {
opts.input.forceUpdate
);
}),
/**
* Get the latest files of a study.
*
* @param studyId - The id of the study.
* @param versionId - The id of the data version. By default not specified for the latest version.
* @param fieldIds - The list of fields to return.
*
* @return IFile[] - The list of objects of IFile.
*/
getFilesLatest: this.baseProcedure.input(z.object({
studyId: z.string(),
versionId: z.optional(z.string()),
fieldIds: z.optional(z.array(z.string())),
readable: z.optional(z.boolean()),
useCache: z.optional(z.boolean()),
forceUpdate: z.optional(z.boolean())
})).query(async (opts) => {
return await this.dataCore.getStudyFilesLatest(
opts.ctx.req.user,
opts.input.studyId,
opts.input.fieldIds,
opts.input.versionId,
opts.input.readable,
opts.input.useCache,
opts.input.forceUpdate
);
}),
/**
* Get the file of a study.
*
Expand Down
Loading

0 comments on commit b995750

Please sign in to comment.