taking array of cancellations and seeded cities of india
This commit is contained in:
@@ -34,14 +34,15 @@ export const handler = safeHandler(async (
|
||||
throw new ApiError(404, 'Host not found');
|
||||
}
|
||||
|
||||
let body: { activityXid: number; venueXid: number; scheduleHeaderXid: number; slotXid: number; cancellationReason?: string };
|
||||
let body: { activityXid: number; venueXid: number; cancellations: { scheduleHeaderXid: number; slotXid: number; cancellationReason: string }[] };
|
||||
|
||||
try {
|
||||
body = event.body ? JSON.parse(event.body) : {};
|
||||
} catch {
|
||||
throw new ApiError(400, 'Invalid JSON payload');
|
||||
}
|
||||
if(!body.activityXid || !body.venueXid || !body.scheduleHeaderXid || !body.slotXid){
|
||||
|
||||
if (!body.activityXid || !body.venueXid || !Array.isArray(body.cancellations) || body.cancellations.length === 0) {
|
||||
throw new ApiError(400, 'Missing required fields');
|
||||
}
|
||||
|
||||
@@ -63,12 +64,15 @@ export const handler = safeHandler(async (
|
||||
}
|
||||
|
||||
|
||||
await schedulingService.cancelSlotForActivity(
|
||||
Number(body.scheduleHeaderXid),
|
||||
Number(body.slotXid),
|
||||
body.cancellationReason || 'No reason provided'
|
||||
await schedulingService.cancelMultipleSlotsForActivity(
|
||||
body.cancellations.map((item: any) => ({
|
||||
scheduleHeaderXid: Number(item.scheduleHeaderXid),
|
||||
slotXid: Number(item.slotXid),
|
||||
cancellationReason: item.cancellationReason
|
||||
}))
|
||||
);
|
||||
|
||||
|
||||
const result = await schedulingService.getVenueDurationByAct(Number(body.activityXid), Number(hostId));
|
||||
|
||||
return {
|
||||
|
||||
@@ -694,24 +694,23 @@ export class SchedulingService {
|
||||
return result;
|
||||
}
|
||||
|
||||
async cancelSlotForActivity(
|
||||
scheduleHeaderXid: number,
|
||||
slotXid?: number,
|
||||
cancellationReason?: string
|
||||
) {
|
||||
return await this.prisma.cancellations.create({
|
||||
data: {
|
||||
scheduleHeader: {
|
||||
connect: { id: scheduleHeaderXid },
|
||||
},
|
||||
slot: {
|
||||
connect: { id: slotXid },
|
||||
},
|
||||
cancellationReason
|
||||
}
|
||||
})
|
||||
async cancelMultipleSlotsForActivity(cancellations: {
|
||||
scheduleHeaderXid: number;
|
||||
slotXid: number;
|
||||
cancellationReason?: string;
|
||||
}[]) {
|
||||
return await this.prisma.cancellations.createMany({
|
||||
data: cancellations.map(item => ({
|
||||
scheduleHeaderXid: item.scheduleHeaderXid,
|
||||
slotXid: item.slotXid,
|
||||
cancellationReason: item.cancellationReason || 'No reason provided'
|
||||
})),
|
||||
skipDuplicates: true
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
async openCanceledSlot(
|
||||
cancellationXid: number,
|
||||
slotXid?: number,
|
||||
|
||||
Reference in New Issue
Block a user