fix: enhance schedule overlap validation in OrderSchema
- Added logic to retrieve existing schedule dates for a given schedule ID to improve overlap detection. - Updated the conditions for checking schedule overlaps to include participant IDs, day of the week, and time slots, ensuring more accurate validation. - This change aims to enhance the integrity of scheduling operations and provide better feedback for users regarding scheduling conflicts.
This commit is contained in:
@@ -401,28 +401,36 @@ export class OrderSchema extends PothosSchema {
|
||||
throw new Error("User has already registered for this service");
|
||||
}
|
||||
// check if user have any scheduledate overlap time with input schedule
|
||||
const scheduleDatesInSchedule =
|
||||
await this.prisma.scheduleDate.findMany({
|
||||
where: {
|
||||
scheduleId: args.data.schedule.connect?.id ?? "",
|
||||
},
|
||||
});
|
||||
const overlapSchedule = await this.prisma.scheduleDate.findFirst({
|
||||
where: {
|
||||
AND: [
|
||||
{
|
||||
start: {
|
||||
equals: args.data.schedule.connect?.scheduleStart as Date,
|
||||
},
|
||||
end: {
|
||||
equals: args.data.schedule.connect?.scheduleEnd as Date,
|
||||
},
|
||||
},
|
||||
{
|
||||
participantIds: {
|
||||
has: ctx.me?.id ?? "",
|
||||
},
|
||||
},
|
||||
{
|
||||
status: {
|
||||
notIn: [
|
||||
ScheduleDateStatus.NOT_STARTED,
|
||||
ScheduleDateStatus.IN_PROGRESS,
|
||||
],
|
||||
orderId: {
|
||||
not: null,
|
||||
},
|
||||
dayOfWeek: {
|
||||
in: Array.isArray(args.data.schedule.connect?.daysOfWeek)
|
||||
? args.data.schedule.connect.daysOfWeek
|
||||
: [],
|
||||
},
|
||||
slot: {
|
||||
in: Array.isArray(args.data.schedule.connect?.slots)
|
||||
? args.data.schedule.connect.slots
|
||||
: [],
|
||||
},
|
||||
scheduleId: {
|
||||
notIn: scheduleDatesInSchedule.map(
|
||||
(scheduleDate) => scheduleDate.scheduleId
|
||||
),
|
||||
},
|
||||
},
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user