change afterbooking api
This commit is contained in:
@@ -28,7 +28,6 @@ export const handler = safeHandler(async (
|
||||
|
||||
let body: {
|
||||
itineraryHeaderXid?: number;
|
||||
activityName?: string;
|
||||
};
|
||||
|
||||
try {
|
||||
@@ -37,18 +36,14 @@ export const handler = safeHandler(async (
|
||||
throw new ApiError(400, 'Invalid JSON in request body');
|
||||
}
|
||||
|
||||
const { itineraryHeaderXid, activityName } = body;
|
||||
const { itineraryHeaderXid } = body;
|
||||
|
||||
if (!itineraryHeaderXid || !activityName) {
|
||||
throw new ApiError(
|
||||
400,
|
||||
'Both itineraryHeaderXid and activityName are required',
|
||||
);
|
||||
if (!itineraryHeaderXid) {
|
||||
throw new ApiError(400, 'itineraryHeaderXid is required');
|
||||
}
|
||||
|
||||
const result = await itineraryService.getActivityDetailsAfterBooking(
|
||||
itineraryHeaderXid,
|
||||
activityName.trim(),
|
||||
);
|
||||
|
||||
return {
|
||||
|
||||
@@ -4512,10 +4512,7 @@ export class ItineraryService {
|
||||
};
|
||||
}
|
||||
|
||||
async getActivityDetailsAfterBooking(
|
||||
itineraryHeaderXid: number,
|
||||
activityName: string,
|
||||
) {
|
||||
async getActivityDetailsAfterBooking(itineraryHeaderXid: number) {
|
||||
// Fetch the itinerary header with complete details
|
||||
const itineraryHeader = await this.prisma.itineraryHeader.findFirst({
|
||||
where: {
|
||||
@@ -4549,34 +4546,24 @@ export class ItineraryService {
|
||||
throw new ApiError(404, 'Itinerary not found');
|
||||
}
|
||||
|
||||
// Parse itinerary start date
|
||||
const startOfDay = new Date(itineraryHeader.fromDate);
|
||||
startOfDay.setHours(0, 0, 0, 0);
|
||||
const endOfDay = new Date(itineraryHeader.fromDate);
|
||||
endOfDay.setHours(23, 59, 59, 999);
|
||||
|
||||
// Find all itinerary activities matching the date and activity name
|
||||
// Find all itinerary activities linked to this itinerary header
|
||||
const itineraryActivities = await this.prisma.itineraryActivities.findMany({
|
||||
where: {
|
||||
itineraryHeaderXid,
|
||||
occurenceDate: {
|
||||
gte: startOfDay,
|
||||
lte: endOfDay,
|
||||
},
|
||||
activity: {
|
||||
activityTitle: {
|
||||
contains: activityName,
|
||||
mode: 'insensitive',
|
||||
},
|
||||
isActive: true,
|
||||
deletedAt: null,
|
||||
activityXid: {
|
||||
not: null,
|
||||
},
|
||||
isActive: true,
|
||||
deletedAt: null,
|
||||
},
|
||||
orderBy: {
|
||||
startTime: 'asc',
|
||||
},
|
||||
orderBy: [
|
||||
{
|
||||
occurenceDate: 'asc',
|
||||
},
|
||||
{
|
||||
startTime: 'asc',
|
||||
},
|
||||
],
|
||||
select: {
|
||||
id: true,
|
||||
occurenceDate: true,
|
||||
@@ -4629,10 +4616,7 @@ export class ItineraryService {
|
||||
});
|
||||
|
||||
if (itineraryActivities.length === 0) {
|
||||
throw new ApiError(
|
||||
404,
|
||||
`No activities found for "${activityName}" on the booked date`,
|
||||
);
|
||||
throw new ApiError(404, 'No activities found for this itinerary');
|
||||
}
|
||||
|
||||
// Process all activities
|
||||
|
||||
Reference in New Issue
Block a user