62 lines
1.8 KiB
TypeScript
62 lines
1.8 KiB
TypeScript
import {
|
|
APIGatewayProxyEvent,
|
|
APIGatewayProxyResult,
|
|
Context,
|
|
} from 'aws-lambda';
|
|
|
|
import { prismaClient } from '../../../../common/database/prisma.lambda.service';
|
|
import { verifyUserToken } from '../../../../common/middlewares/jwt/authForUser';
|
|
import { safeHandler } from '../../../../common/utils/handlers/safeHandler';
|
|
import ApiError from '../../../../common/utils/helper/ApiError';
|
|
import { ItineraryService } from '../../services/itinerary.service';
|
|
|
|
const itineraryService = new ItineraryService(prismaClient);
|
|
|
|
export const handler = safeHandler(async (
|
|
event: APIGatewayProxyEvent,
|
|
context?: Context,
|
|
): Promise<APIGatewayProxyResult> => {
|
|
const token = event.headers['x-auth-token'] || event.headers['X-Auth-Token'];
|
|
if (!token) {
|
|
throw new ApiError(
|
|
400,
|
|
'This is a protected route. Please provide a valid token.',
|
|
);
|
|
}
|
|
|
|
const userInfo = await verifyUserToken(token);
|
|
const userId = Number(userInfo.id);
|
|
|
|
if (!userId || Number.isNaN(userId)) {
|
|
throw new ApiError(400, 'Invalid user ID');
|
|
}
|
|
|
|
const itineraryHeaderXidRaw = event.queryStringParameters?.itineraryHeaderXid;
|
|
if (!itineraryHeaderXidRaw) {
|
|
throw new ApiError(400, 'itineraryHeaderXid is required.');
|
|
}
|
|
|
|
const itineraryHeaderXid = Number(itineraryHeaderXidRaw);
|
|
if (!Number.isInteger(itineraryHeaderXid) || itineraryHeaderXid <= 0) {
|
|
throw new ApiError(400, 'Invalid itineraryHeaderXid.');
|
|
}
|
|
|
|
const result = await itineraryService.getItineraryCheckoutDetails(
|
|
userId,
|
|
itineraryHeaderXid,
|
|
);
|
|
|
|
return {
|
|
statusCode: 200,
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
'Access-Control-Allow-Origin': '*',
|
|
},
|
|
body: JSON.stringify({
|
|
success: true,
|
|
message: 'Itinerary checkout details retrieved successfully',
|
|
data: result,
|
|
}),
|
|
};
|
|
});
|