add prepopulateTeammate function to retrieve roles for Coadmin and Account_manager

This commit is contained in:
paritosh18
2025-11-14 16:33:14 +05:30
parent f8a405204f
commit d8f08bf564
2 changed files with 68 additions and 0 deletions

View File

@@ -259,6 +259,22 @@ functions:
method: post
prepopulateTeammate:
handler: src/modules/minglaradmin/handlers/prepopulateTeammate.handler
package:
patterns:
- "src/modules/minglaradmin/**"
- "common/**"
- "src/common/**"
- "node_modules/@prisma/client/**"
- "node_modules/.prisma/**"
events:
- httpApi:
path: /minglaradmin/prepopulate-teammate
method: get
addCompanyDetails:
handler: src/modules/host/handlers/addCompanyDetails.handler
package:

View File

@@ -0,0 +1,52 @@
import { APIGatewayProxyEvent, APIGatewayProxyResult, Context } from 'aws-lambda';
import { safeHandler } from '../../../common/utils/handlers/safeHandler';
import { PrismaService } from '../../../common/database/prisma.service';
import ApiError from '../../../common/utils/helper/ApiError';
import { ROLE } from '../../../common/utils/constants/common.constant';
const prismaService = new PrismaService();
/**
* Get prepopulated roles for Coadmin and Account_manager
* Returns an array of role objects with their IDs
*/
export const handler = safeHandler(async (
event: APIGatewayProxyEvent,
context?: Context
): Promise<APIGatewayProxyResult> => {
// Fetch Coadmin and Account_Manager roles
const roles = await prismaService.roles.findMany({
where: {
id: {
in: [ROLE.CO_ADMIN, ROLE.ACCOUNT_MANAGER]
},
isActive: true,
deletedAt: null
},
select: {
id: true,
roleName: true
},
orderBy: {
id: 'asc'
}
});
if (!roles || roles.length === 0) {
throw new ApiError(404, 'No roles found for Coadmin or Account_manager');
}
return {
statusCode: 200,
headers: {
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': '*',
},
body: JSON.stringify({
success: true,
message: 'Roles retrieved successfully',
data: roles,
count: roles.length
}),
};
});