chore: fix upsert resume

This commit is contained in:
2024-12-16 17:09:19 +07:00
parent 11f234522b
commit b6b97acdec
2 changed files with 25 additions and 2 deletions

View File

@@ -153,7 +153,30 @@ export class CenterSchema extends PothosSchema {
required: true,
}),
},
resolve: async (query, _root, args) => {
resolve: async (query, _root, args, ctx) => {
if (ctx.isSubscription) {
throw new Error('Not allowed in subscription')
}
if (ctx.http.me?.role !== Role.CUSTOMER) {
throw new Error('Not allowed')
}
// check if user has already created a center
const existingCenter = await this.prisma.center.findFirst({
where: {
centerOwnerId: ctx.http.me?.id,
},
})
if (existingCenter) {
if (existingCenter.centerStatus === CenterStatus.PENDING) {
throw new Error('User has already created a center but is pending approval')
}
if (existingCenter.centerStatus === CenterStatus.APPROVED) {
throw new Error('User has already created a center and is approved')
}
if (existingCenter.centerStatus === CenterStatus.REJECTED) {
throw new Error('User has already created a center and is rejected')
}
}
return await this.prisma.center.create({
...query,
data: args.input,

View File

@@ -208,7 +208,7 @@ export class ResumeSchema extends PothosSchema {
if (ctx.isSubscription) {
throw new Error('Not allowed')
}
if (ctx.http.me?.role !== Role.CUSTOMER) {
if (ctx.http.me?.role !== Role.CUSTOMER && ctx.http.me?.role !== Role.CENTER_OWNER) {
throw new Error('Not allowed')
}
const { resumeFile } = args