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:
2025-01-17 20:59:05 +07:00
parent c2d3ebba09
commit b33ad5e809

View File

@@ -401,28 +401,36 @@ export class OrderSchema extends PothosSchema {
throw new Error("User has already registered for this service"); throw new Error("User has already registered for this service");
} }
// check if user have any scheduledate overlap time with input schedule // 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({ const overlapSchedule = await this.prisma.scheduleDate.findFirst({
where: { where: {
AND: [ AND: [
{
start: {
equals: args.data.schedule.connect?.scheduleStart as Date,
},
end: {
equals: args.data.schedule.connect?.scheduleEnd as Date,
},
},
{ {
participantIds: { participantIds: {
has: ctx.me?.id ?? "", has: ctx.me?.id ?? "",
}, },
}, orderId: {
{ not: null,
status: { },
notIn: [ dayOfWeek: {
ScheduleDateStatus.NOT_STARTED, in: Array.isArray(args.data.schedule.connect?.daysOfWeek)
ScheduleDateStatus.IN_PROGRESS, ? 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
),
}, },
}, },
], ],