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
|
// Mutations section
|
||||||
this.builder.mutationFields((t) => ({
|
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(),
|
type: this.resume(),
|
||||||
args: {
|
args: {
|
||||||
userId: t.arg({
|
where: t.arg({
|
||||||
type: 'String',
|
type: this.builder.generator.getWhereUnique('Resume'),
|
||||||
required: true,
|
|
||||||
}),
|
|
||||||
centerId: t.arg({
|
|
||||||
type: 'String',
|
|
||||||
required: true,
|
required: true,
|
||||||
}),
|
}),
|
||||||
resumeFile: t.arg({
|
resumeFile: t.arg({
|
||||||
@@ -152,7 +192,7 @@ export class ResumeSchema extends PothosSchema {
|
|||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
resolve: async (query, root, args, ctx, info) => {
|
resolve: async (query, root, args, ctx, info) => {
|
||||||
const { userId, centerId, resumeFile } = args;
|
const { resumeFile } = args;
|
||||||
const { mimetype } = await resumeFile;
|
const { mimetype } = await resumeFile;
|
||||||
const { filename } = await this.minioService.uploadFile(
|
const { filename } = await this.minioService.uploadFile(
|
||||||
resumeFile,
|
resumeFile,
|
||||||
@@ -162,10 +202,32 @@ export class ResumeSchema extends PothosSchema {
|
|||||||
filename,
|
filename,
|
||||||
'resumes',
|
'resumes',
|
||||||
);
|
);
|
||||||
const resume = await this.prisma.resume.create({
|
const { userId, centerId } = args.where as {
|
||||||
data: {
|
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,
|
userId,
|
||||||
centerId,
|
centerId,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
create: {
|
||||||
|
userId,
|
||||||
|
centerId,
|
||||||
|
ResumeFile: {
|
||||||
|
create: {
|
||||||
|
fileUrl,
|
||||||
|
type: mimetype,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
update: {
|
||||||
ResumeFile: {
|
ResumeFile: {
|
||||||
create: {
|
create: {
|
||||||
fileUrl,
|
fileUrl,
|
||||||
|
|||||||
@@ -26,7 +26,9 @@ export class WorkshopSchema extends PothosSchema {
|
|||||||
description: t.exposeString('description'),
|
description: t.exposeString('description'),
|
||||||
staffId: t.exposeID('staffId'),
|
staffId: t.exposeID('staffId'),
|
||||||
serviceId: t.exposeID('serviceId'),
|
serviceId: t.exposeID('serviceId'),
|
||||||
imageFile: t.relation('imageFile'),
|
imageFile: t.relation('imageFile', {
|
||||||
|
nullable: true,
|
||||||
|
}),
|
||||||
imageFileId: t.exposeID('imageFileId'),
|
imageFileId: t.exposeID('imageFileId'),
|
||||||
imageFileUrl: t.exposeString('imageFileUrl'),
|
imageFileUrl: t.exposeString('imageFileUrl'),
|
||||||
date: t.expose('date', {
|
date: t.expose('date', {
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user