chore: fix order and schedule creation logic
This commit is contained in:
@@ -278,13 +278,14 @@ export class ScheduleSchema extends PothosSchema {
|
||||
return schedules
|
||||
}
|
||||
// use case 2: center mentor or center owner query schedules where center mentor or center owner is mentor
|
||||
else if (ctx.http.me.role === Role.CENTER_MENTOR || ctx.http.me.role === Role.CENTER_OWNER) {
|
||||
if (ctx.http.me.role === Role.CENTER_MENTOR) {
|
||||
const center = await this.prisma.center.findFirst({
|
||||
where: {
|
||||
OR: [{ centerOwnerId: ctx.http.me.id }, { centerMentors: { some: { mentorId: ctx.http.me.id } } }],
|
||||
},
|
||||
include: {
|
||||
centerMentors: true,
|
||||
centerMentors: {
|
||||
some: {
|
||||
mentorId: ctx.http.me.id,
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
if (!center) {
|
||||
@@ -298,19 +299,32 @@ export class ScheduleSchema extends PothosSchema {
|
||||
orderBy: args.orderBy ?? undefined,
|
||||
where: {
|
||||
AND: [
|
||||
{ managedService: { service: { centerId: center.id } } },
|
||||
{
|
||||
OR: [
|
||||
{ customerId: ctx.http.me.id },
|
||||
{ dates: { some: { participantIds: { has: ctx.http.me.id } } } },
|
||||
],
|
||||
},
|
||||
{ managedService: { service: { centerId: center.id }, mentorId: ctx.http.me.id } },
|
||||
...(args.filter ? [args.filter] : []),
|
||||
],
|
||||
},
|
||||
})
|
||||
return schedules
|
||||
}
|
||||
// use case 3: Center owner query all schedules belong to center
|
||||
if (ctx.http.me.role === Role.CENTER_OWNER) {
|
||||
const center = await this.prisma.center.findFirst({
|
||||
where: { centerOwnerId: ctx.http.me.id },
|
||||
})
|
||||
if (!center) {
|
||||
throw new Error('Center not found')
|
||||
}
|
||||
const schedules = await this.prisma.schedule.findMany({
|
||||
...query,
|
||||
where: {
|
||||
AND: [{ managedService: { service: { centerId: center.id } } }, ...(args.filter ? [args.filter] : [])],
|
||||
},
|
||||
orderBy: args.orderBy ?? undefined,
|
||||
skip: args.skip ?? undefined,
|
||||
take: args.take ?? undefined,
|
||||
})
|
||||
return schedules
|
||||
}
|
||||
},
|
||||
}),
|
||||
|
||||
|
||||
Reference in New Issue
Block a user