handle resume file upload and url

This commit is contained in:
2024-10-15 01:18:39 +07:00
parent 5a5a53c0c9
commit dc81f6eaa8
3 changed files with 143 additions and 5 deletions

View File

@@ -41,23 +41,44 @@ export class UploadedFileSchema extends PothosSchema {
type: this.uploadedFile(),
args: this.builder.generator.findUniqueArgs('UploadedFile'),
resolve: async (query, root, args, ctx, info) => {
return await this.prisma.uploadedFile.findUnique({
const file = await this.prisma.uploadedFile.findUnique({
...query,
where: args.where,
});
if (!file) {
throw new Error('File not found');
}
const fileUrl = await this.minioService.getFileUrl(
file.fileName,
'files',
);
if (!fileUrl) {
throw new Error('Cannot retrieve file url');
}
file.fileUrl = fileUrl;
return file;
},
}),
uploadedDocuments: t.prismaField({
type: [this.uploadedFile()],
args: this.builder.generator.findManyArgs('UploadedFile'),
resolve: async (query, root, args, ctx, info) => {
return await this.prisma.uploadedFile.findMany({
const files = await this.prisma.uploadedFile.findMany({
...query,
skip: args.skip ?? 0,
take: args.take ?? 10,
orderBy: args.orderBy ?? undefined,
where: args.filter ?? undefined,
});
const fileUrls = await Promise.all(
files.map((file) =>
this.minioService.getFileUrl(file.fileName, 'files'),
),
);
return files.map((file, index) => ({
...file,
fileUrl: fileUrls[index],
}));
},
}),
}));