handle resume file upload and url
This commit is contained in:
@@ -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],
|
||||
}));
|
||||
},
|
||||
}),
|
||||
}));
|
||||
|
||||
Reference in New Issue
Block a user