Merge branch 'mayankSprint2' of http://git.wdipl.com/Mayank.Mishra/MinglarBackendNestJS into paritosh-main1

This commit is contained in:
paritosh18
2026-02-26 19:45:30 +05:30
3 changed files with 65 additions and 53 deletions

View File

@@ -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
}))
);

View File

@@ -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),
})),
);

View File

@@ -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,13 +307,20 @@ 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) => ({
const slots = header.ScheduleDetails
.filter(
(slot) =>
!cancelledSlots.has(`${slot.startTime}-${slot.endTime}`)
)
.map((slot) => ({
slotId: slot.id,
startTime: slot.startTime,
endTime: slot.endTime,
@@ -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,13 +397,20 @@ 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) => ({
const slots = header.ScheduleDetails
.filter(
(slot) =>
!cancelledSlots.has(`${slot.startTime}-${slot.endTime}`)
)
.map((slot) => ({
slotId: slot.id,
occurenceDate: slot.occurenceDate,
weekDay: slot.weekDay,
@@ -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,
},
},
},
},
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: {