diff --git a/src/Center/center.schema.ts b/src/Center/center.schema.ts index 034e110..d485ec5 100644 --- a/src/Center/center.schema.ts +++ b/src/Center/center.schema.ts @@ -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, diff --git a/src/Resume/resume.schema.ts b/src/Resume/resume.schema.ts index 90f694b..b2174af 100644 --- a/src/Resume/resume.schema.ts +++ b/src/Resume/resume.schema.ts @@ -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