fixed the service code and added validation
This commit is contained in:
@@ -34,13 +34,16 @@ 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; 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){
|
||||
throw new ApiError(400, 'Missing required fields');
|
||||
}
|
||||
|
||||
const activity = await schedulingService.getActivityByXid(body.activityXid);
|
||||
if (!activity) {
|
||||
|
||||
@@ -508,11 +508,15 @@ export class SchedulingService {
|
||||
scheduleHeaderXid: number,
|
||||
slotXid?: number,
|
||||
cancellationReason?: string
|
||||
){
|
||||
) {
|
||||
return await this.prisma.cancellations.create({
|
||||
data: {
|
||||
scheduleHeaderXid,
|
||||
slotXid,
|
||||
scheduleHeader: {
|
||||
connect: { id: scheduleHeaderXid },
|
||||
},
|
||||
slot: {
|
||||
connect: { id: slotXid },
|
||||
},
|
||||
cancellationReason
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user