51 lines
1.6 KiB
TypeScript
51 lines
1.6 KiB
TypeScript
import { PrismaService } from '../../../../../common/database/prisma.service';
|
|
import { verifyMinglarAdminToken } from '../../../../../common/middlewares/jwt/authForMinglarAdmin';
|
|
import { safeHandler } from '../../../../../common/utils/handlers/safeHandler';
|
|
import ApiError from '../../../../../common/utils/helper/ApiError';
|
|
import { APIGatewayProxyEvent, APIGatewayProxyResult, Context } from 'aws-lambda';
|
|
import { MinglarService } from '../../../services/minglar.service';
|
|
|
|
const prismaService = new PrismaService();
|
|
const minglarService = new MinglarService(prismaService);
|
|
|
|
export const handler = safeHandler(async (
|
|
event: APIGatewayProxyEvent,
|
|
context?: Context
|
|
): Promise<APIGatewayProxyResult> => {
|
|
// Get host ID from path parameters
|
|
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.');
|
|
}
|
|
|
|
await verifyMinglarAdminToken(token);
|
|
|
|
const host_xid = event.pathParameters?.host_xid;
|
|
if (!host_xid) {
|
|
throw new ApiError(
|
|
400,
|
|
'Host ID is required in path parameters.',
|
|
);
|
|
}
|
|
|
|
|
|
const hostDetails = await minglarService.getHostDetailsById(Number(host_xid));
|
|
|
|
if (!hostDetails) {
|
|
throw new ApiError(404, 'Host not found');
|
|
}
|
|
|
|
return {
|
|
statusCode: 200,
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
'Access-Control-Allow-Origin': '*',
|
|
},
|
|
body: JSON.stringify({
|
|
success: true,
|
|
message: 'Host details retrieved successfully',
|
|
data: hostDetails,
|
|
}),
|
|
};
|
|
});
|