using upsert instead create new resume
This commit is contained in:
Submodule epess-database updated: 90a1bf3709...05d6fc8fb4
@@ -135,15 +135,55 @@ export class ResumeSchema extends PothosSchema {
|
||||
|
||||
// Mutations section
|
||||
this.builder.mutationFields((t) => ({
|
||||
createResume: t.prismaField({
|
||||
// createResume: t.prismaField({
|
||||
// type: this.resume(),
|
||||
// args: {
|
||||
// userId: t.arg({
|
||||
// type: 'String',
|
||||
// required: true,
|
||||
// }),
|
||||
// centerId: t.arg({
|
||||
// type: 'String',
|
||||
// required: true,
|
||||
// }),
|
||||
// resumeFile: t.arg({
|
||||
// type: 'Upload',
|
||||
// required: true,
|
||||
// }),
|
||||
// },
|
||||
// resolve: async (query, root, args, ctx, info) => {
|
||||
// const { userId, centerId, resumeFile } = args;
|
||||
// const { mimetype } = await resumeFile;
|
||||
// const { filename } = await this.minioService.uploadFile(
|
||||
// resumeFile,
|
||||
// 'resumes',
|
||||
// );
|
||||
// const fileUrl = await this.minioService.getFileUrl(
|
||||
// filename,
|
||||
// 'resumes',
|
||||
// );
|
||||
// const resume = await this.prisma.resume.create({
|
||||
// data: {
|
||||
// userId,
|
||||
// centerId,
|
||||
// ResumeFile: {
|
||||
// create: {
|
||||
// fileUrl,
|
||||
// type: mimetype,
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// });
|
||||
|
||||
// return resume;
|
||||
// },
|
||||
// }),
|
||||
|
||||
upsertResume: t.prismaField({
|
||||
type: this.resume(),
|
||||
args: {
|
||||
userId: t.arg({
|
||||
type: 'String',
|
||||
required: true,
|
||||
}),
|
||||
centerId: t.arg({
|
||||
type: 'String',
|
||||
where: t.arg({
|
||||
type: this.builder.generator.getWhereUnique('Resume'),
|
||||
required: true,
|
||||
}),
|
||||
resumeFile: t.arg({
|
||||
@@ -152,7 +192,7 @@ export class ResumeSchema extends PothosSchema {
|
||||
}),
|
||||
},
|
||||
resolve: async (query, root, args, ctx, info) => {
|
||||
const { userId, centerId, resumeFile } = args;
|
||||
const { resumeFile } = args;
|
||||
const { mimetype } = await resumeFile;
|
||||
const { filename } = await this.minioService.uploadFile(
|
||||
resumeFile,
|
||||
@@ -162,10 +202,32 @@ export class ResumeSchema extends PothosSchema {
|
||||
filename,
|
||||
'resumes',
|
||||
);
|
||||
const resume = await this.prisma.resume.create({
|
||||
data: {
|
||||
const { userId, centerId } = args.where as {
|
||||
userId: string;
|
||||
centerId: string | null;
|
||||
};
|
||||
if (!userId || !centerId) {
|
||||
throw new Error('userId and centerId are required');
|
||||
}
|
||||
const resume = await this.prisma.resume.upsert({
|
||||
...query,
|
||||
where: {
|
||||
userId_centerId: {
|
||||
userId,
|
||||
centerId,
|
||||
},
|
||||
},
|
||||
create: {
|
||||
userId,
|
||||
centerId,
|
||||
ResumeFile: {
|
||||
create: {
|
||||
fileUrl,
|
||||
type: mimetype,
|
||||
},
|
||||
},
|
||||
},
|
||||
update: {
|
||||
ResumeFile: {
|
||||
create: {
|
||||
fileUrl,
|
||||
|
||||
@@ -26,7 +26,9 @@ export class WorkshopSchema extends PothosSchema {
|
||||
description: t.exposeString('description'),
|
||||
staffId: t.exposeID('staffId'),
|
||||
serviceId: t.exposeID('serviceId'),
|
||||
imageFile: t.relation('imageFile'),
|
||||
imageFile: t.relation('imageFile', {
|
||||
nullable: true,
|
||||
}),
|
||||
imageFileId: t.exposeID('imageFileId'),
|
||||
imageFileUrl: t.exposeString('imageFileUrl'),
|
||||
date: t.expose('date', {
|
||||
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user