diff --git a/src/modules/host/handlers/Activity_Hub/Scheduling/cancelSlot.ts b/src/modules/host/handlers/Activity_Hub/Scheduling/cancelSlot.ts index 69a20bc..2ad0f4c 100644 --- a/src/modules/host/handlers/Activity_Hub/Scheduling/cancelSlot.ts +++ b/src/modules/host/handlers/Activity_Hub/Scheduling/cancelSlot.ts @@ -32,7 +32,17 @@ export const handler = safeHandler(async ( throw new ApiError(404, 'Host not found'); } - let body: { activityXid: number; venueXid: number; cancellations: { scheduleHeaderXid: number; slotXid: number; cancellationReason: string }[] }; + let body: { + activityXid: number; + venueXid: number; + cancellations: { + scheduleHeaderXid: number; + occurenceDate: string; + startTime: string; + endTime: string; + cancellationReason: string + }[] + }; try { body = event.body ? JSON.parse(event.body) : {}; @@ -65,7 +75,9 @@ export const handler = safeHandler(async ( await schedulingService.cancelMultipleSlotsForActivity( body.cancellations.map((item: any) => ({ scheduleHeaderXid: Number(item.scheduleHeaderXid), - slotXid: Number(item.slotXid), + occurenceDate: item.occurenceDate, + startTime: item.startTime, + endTime: item.endTime, cancellationReason: item.cancellationReason })) ); diff --git a/src/modules/host/handlers/Activity_Hub/Scheduling/openCanceledSlot.ts b/src/modules/host/handlers/Activity_Hub/Scheduling/openCanceledSlot.ts index aa4fac2..2eaaa9e 100644 --- a/src/modules/host/handlers/Activity_Hub/Scheduling/openCanceledSlot.ts +++ b/src/modules/host/handlers/Activity_Hub/Scheduling/openCanceledSlot.ts @@ -44,7 +44,7 @@ export const handler = safeHandler( let body: { activityXid: number; venueXid: number; - cancellations: { cancellationXid: number; slotXid: number }[]; + cancellations: { cancellationXid: number; }[]; }; try { @@ -79,7 +79,6 @@ export const handler = safeHandler( await schedulingService.openCanceledSlot( body.cancellations.map((item: any) => ({ cancellationXid: Number(item.cancellationXid), - slotXid: Number(item.slotXid), })), ); diff --git a/src/modules/host/services/activityScheduling.service.ts b/src/modules/host/services/activityScheduling.service.ts index 36cab6b..82ace3c 100644 --- a/src/modules/host/services/activityScheduling.service.ts +++ b/src/modules/host/services/activityScheduling.service.ts @@ -16,7 +16,7 @@ const bucket = config.aws.bucketName; @Injectable() export class SchedulingService { - constructor(private prisma: PrismaClient) {} + constructor(private prisma: PrismaClient) { } async getHostIdByUserId(userId: number) { const host = await this.prisma.hostHeader.findFirst({ @@ -307,18 +307,25 @@ export class SchedulingService { const response = []; for (const header of scheduleHeaders) { - const cancelledSlotIds = new Set( - header.Cancellations.map((c) => c.slotXid), + + // Build cancellation set using time matching + const cancelledSlots = new Set( + header.Cancellations.map( + (c) => `${c.startTime}-${c.endTime}` + ) ); - const slots = header.ScheduleDetails.filter( - (slot) => !cancelledSlotIds.has(slot.id), - ).map((slot) => ({ - slotId: slot.id, - startTime: slot.startTime, - endTime: slot.endTime, - maxCapacity: slot.maxCapacity, - })); + const slots = header.ScheduleDetails + .filter( + (slot) => + !cancelledSlots.has(`${slot.startTime}-${slot.endTime}`) + ) + .map((slot) => ({ + slotId: slot.id, + startTime: slot.startTime, + endTime: slot.endTime, + maxCapacity: slot.maxCapacity, + })); if (!slots.length) continue; @@ -326,6 +333,7 @@ export class SchedulingService { venueXid: header.activityVenue.id, venueName: header.activityVenue.venueName, venueLabel: header.activityVenue.venueLabel, + venueCapacity: header.activityVenue.venueCapacity, slots, }); } @@ -389,21 +397,28 @@ export class SchedulingService { if (!scheduleHeaders.length) return []; const response = scheduleHeaders.map((header) => { - const cancelledSlotIds = new Set( - header.Cancellations.map((c) => c.slotXid), + + // Match cancelled slots using startTime + endTime + const cancelledSlots = new Set( + header.Cancellations.map( + (c) => `${c.startTime}-${c.endTime}` + ) ); - const slots = header.ScheduleDetails.filter( - (slot) => !cancelledSlotIds.has(slot.id), - ).map((slot) => ({ - slotId: slot.id, - occurenceDate: slot.occurenceDate, - weekDay: slot.weekDay, - dayOfMonth: slot.dayOfMonth, - startTime: slot.startTime, - endTime: slot.endTime, - maxCapacity: slot.maxCapacity, - })); + const slots = header.ScheduleDetails + .filter( + (slot) => + !cancelledSlots.has(`${slot.startTime}-${slot.endTime}`) + ) + .map((slot) => ({ + slotId: slot.id, + occurenceDate: slot.occurenceDate, + weekDay: slot.weekDay, + dayOfMonth: slot.dayOfMonth, + startTime: slot.startTime, + endTime: slot.endTime, + maxCapacity: slot.maxCapacity, + })); return { scheduleHeaderXid: header.id, @@ -418,7 +433,7 @@ export class SchedulingService { venueLabel: header.activityVenue.venueLabel, venueCapacity: header.activityVenue.venueCapacity, }, - slots, + slots, // only active slots, no cancellation flag }; }); @@ -586,18 +601,10 @@ export class SchedulingService { where: { isActive: true }, select: { id: true, - slotXid: true, cancellationReason: true, - slot: { - select: { - id: true, - occurenceDate: true, - startTime: true, - endTime: true, - weekDay: true, - dayOfMonth: true, - }, - }, + occurenceDate: true, + startTime: true, + endTime: true, }, }, scheduleOccurences: { @@ -646,16 +653,6 @@ export class SchedulingService { for (const venue of result.ActivityVenues ?? []) { for (const header of venue.ScheduleHeader ?? []) { - /* ------------------------------- - 🚫 SLOT CANCELLATION FLAG - -------------------------------- */ - const cancelledSlotIds = new Set( - header.Cancellations?.map((c) => c.slotXid), - ); - - for (const slot of header.ScheduleDetails ?? []) { - (slot as any).isCancelled = cancelledSlotIds.has(slot.id); - } /* ------------------------------- 📅 FRONTEND FRIENDLY META @@ -710,14 +707,18 @@ export class SchedulingService { async cancelMultipleSlotsForActivity( cancellations: { scheduleHeaderXid: number; - slotXid: number; + occurenceDate: string; + startTime: string; + endTime: string; cancellationReason?: string; }[], ) { return await this.prisma.cancellations.createMany({ data: cancellations.map((item) => ({ scheduleHeaderXid: item.scheduleHeaderXid, - slotXid: item.slotXid, + occurenceDate: item.occurenceDate, + startTime: item.startTime, + endTime: item.endTime, cancellationReason: item.cancellationReason || 'No reason provided', })), skipDuplicates: true, @@ -725,7 +726,7 @@ export class SchedulingService { } async openCanceledSlot( - cancellations: { cancellationXid: number; slotXid: number }[], + cancellations: { cancellationXid: number; }[], ) { return await this.prisma.cancellations.updateMany({ where: {