60 lines
1.4 KiB
TypeScript
60 lines
1.4 KiB
TypeScript
import {
|
|
APIGatewayProxyEvent,
|
|
APIGatewayProxyResult,
|
|
Context,
|
|
} from 'aws-lambda';
|
|
|
|
import { prismaClient } from '../../../../common/database/prisma.lambda.service';
|
|
import { verifyHostToken } from '../../../../common/middlewares/jwt/authForHost';
|
|
import { ROLE } from '../../../../common/utils/constants/common.constant';
|
|
import { safeHandler } from '../../../../common/utils/handlers/safeHandler';
|
|
import ApiError from '../../../../common/utils/helper/ApiError';
|
|
|
|
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.',
|
|
);
|
|
}
|
|
|
|
await verifyHostToken(token);
|
|
|
|
const roles = await prismaClient.roles.findMany({
|
|
where: {
|
|
id: {
|
|
in: [ROLE.CO_ADMIN, ROLE.OPERATOR],
|
|
},
|
|
isActive: true,
|
|
deletedAt: null,
|
|
},
|
|
select: {
|
|
id: true,
|
|
roleName: true,
|
|
},
|
|
orderBy: {
|
|
id: 'asc',
|
|
},
|
|
});
|
|
|
|
return {
|
|
statusCode: 200,
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
'Access-Control-Allow-Origin': '*',
|
|
},
|
|
body: JSON.stringify({
|
|
success: true,
|
|
message: 'Host member roles fetched successfully',
|
|
data: {
|
|
roles,
|
|
},
|
|
}),
|
|
};
|
|
});
|