changed logic form filter only with start date
This commit is contained in:
@@ -485,7 +485,7 @@ saveItineraryActivitySelections:
|
||||
|
||||
getAllUserSavedItineraries:
|
||||
handler: src/modules/user/handlers/itinerary/getAllUserSavedItineraries.handler
|
||||
memorySize: 512
|
||||
memorySize: 1024
|
||||
package:
|
||||
patterns:
|
||||
- 'src/modules/user/**'
|
||||
|
||||
@@ -60,7 +60,6 @@ export const handler = safeHandler(async (
|
||||
const itineraryHeaderXidRaw =
|
||||
event.queryStringParameters?.itineraryHeaderXid ?? null;
|
||||
const startDateRaw = event.queryStringParameters?.startDate ?? null;
|
||||
const endDateRaw = event.queryStringParameters?.endDate ?? null;
|
||||
|
||||
let itineraryHeaderXid: number | undefined;
|
||||
if (
|
||||
@@ -79,38 +78,17 @@ export const handler = safeHandler(async (
|
||||
startDateRaw !== null &&
|
||||
startDateRaw !== undefined &&
|
||||
startDateRaw.trim() !== '';
|
||||
const hasEndDate =
|
||||
endDateRaw !== null &&
|
||||
endDateRaw !== undefined &&
|
||||
endDateRaw.trim() !== '';
|
||||
|
||||
if (hasStartDate !== hasEndDate) {
|
||||
throw new ApiError(
|
||||
400,
|
||||
'startDate and endDate must be provided together',
|
||||
);
|
||||
}
|
||||
|
||||
let startDate: Date | undefined;
|
||||
let endDate: Date | undefined;
|
||||
|
||||
if (hasStartDate && hasEndDate) {
|
||||
if (hasStartDate) {
|
||||
startDate = parseQueryDate(startDateRaw, 'startDate');
|
||||
endDate = parseQueryDate(endDateRaw, 'endDate');
|
||||
|
||||
if (startDate > endDate) {
|
||||
throw new ApiError(
|
||||
400,
|
||||
'startDate must be earlier than or equal to endDate',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
const result = await itineraryService.getAllUserSavedItineraries(
|
||||
userId,
|
||||
itineraryHeaderXid,
|
||||
startDate,
|
||||
endDate,
|
||||
);
|
||||
|
||||
return {
|
||||
|
||||
@@ -1801,19 +1801,15 @@ export class ItineraryService {
|
||||
userXid: number,
|
||||
itineraryHeaderXid?: number,
|
||||
startDate?: Date,
|
||||
endDate?: Date,
|
||||
) {
|
||||
const itineraries = await this.prisma.itineraryHeader.findMany({
|
||||
where: {
|
||||
...(itineraryHeaderXid ? { id: itineraryHeaderXid } : {}),
|
||||
...(startDate && endDate
|
||||
...(startDate
|
||||
? {
|
||||
fromDate: {
|
||||
gte: startDate,
|
||||
},
|
||||
toDate: {
|
||||
lte: endDate,
|
||||
},
|
||||
}
|
||||
: {}),
|
||||
isActive: true,
|
||||
|
||||
Reference in New Issue
Block a user