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");
|
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,
|
||||||
},
|
},
|
||||||
{
|
dayOfWeek: {
|
||||||
status: {
|
in: Array.isArray(args.data.schedule.connect?.daysOfWeek)
|
||||||
notIn: [
|
? args.data.schedule.connect.daysOfWeek
|
||||||
ScheduleDateStatus.NOT_STARTED,
|
: [],
|
||||||
ScheduleDateStatus.IN_PROGRESS,
|
},
|
||||||
],
|
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