66 lines
2.0 KiB
TypeScript
66 lines
2.0 KiB
TypeScript
|
|
import {
|
||
|
|
APIGatewayProxyEvent,
|
||
|
|
APIGatewayProxyResult,
|
||
|
|
Context,
|
||
|
|
} from 'aws-lambda';
|
||
|
|
import { prismaClient } from '../../../../common/database/prisma.lambda.service';
|
||
|
|
import { verifyOperatorToken } from '../../../../common/middlewares/jwt/authForHost';
|
||
|
|
import { safeHandler } from '../../../../common/utils/handlers/safeHandler';
|
||
|
|
import ApiError from '../../../../common/utils/helper/ApiError';
|
||
|
|
import { GetReservationByCheckInCodeRequestDTO } from '../../dto/operator.activity.dto';
|
||
|
|
import { OperatorActivityService } from '../../services/operatorActivity.service';
|
||
|
|
|
||
|
|
const operatorActivityService = new OperatorActivityService(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 operatorInfo = await verifyOperatorToken(token);
|
||
|
|
const operatorId = Number(operatorInfo.id);
|
||
|
|
|
||
|
|
if (!operatorId || Number.isNaN(operatorId)) {
|
||
|
|
throw new ApiError(400, 'Invalid operator ID');
|
||
|
|
}
|
||
|
|
|
||
|
|
const requestDTO: GetReservationByCheckInCodeRequestDTO = {
|
||
|
|
checkInCode:
|
||
|
|
event.queryStringParameters?.checkInCode?.trim() ||
|
||
|
|
event.queryStringParameters?.offlineCode?.trim() ||
|
||
|
|
'',
|
||
|
|
};
|
||
|
|
|
||
|
|
if (!requestDTO.checkInCode) {
|
||
|
|
throw new ApiError(400, 'checkInCode is required.');
|
||
|
|
}
|
||
|
|
|
||
|
|
const result = await operatorActivityService.getReservationByCheckInCode(
|
||
|
|
operatorId,
|
||
|
|
requestDTO.checkInCode,
|
||
|
|
);
|
||
|
|
|
||
|
|
return {
|
||
|
|
statusCode: 200,
|
||
|
|
headers: {
|
||
|
|
'Content-Type': 'application/json',
|
||
|
|
'Access-Control-Allow-Origin': '*',
|
||
|
|
},
|
||
|
|
body: JSON.stringify({
|
||
|
|
success: true,
|
||
|
|
message: 'Reservation details fetched successfully',
|
||
|
|
data: result,
|
||
|
|
}),
|
||
|
|
};
|
||
|
|
},
|
||
|
|
);
|