- Updated `resendOtp.ts` to parse and validate request body using Zod. - Refactored `createPassword.ts` to utilize Zod for body validation. - Modified `getAMDetail_ById.ts` to implement Zod for path parameter validation. - Changed `acceptHostApplication.ts` to use Zod for request body validation. - Updated `addPQQSuggestion.ts` to validate request body with Zod. - Refactored `addSuggestion.ts` to use Zod for body validation. - Modified `getAllHostApplicationForAM.ts` to implement Zod for query parameter validation. - Changed `getByIdHostDetails.ts` to use Zod for path parameter validation. - Updated `rejectHostApplicationAM.ts` to validate request body with Zod. - Refactored `rejectPQQbyAM.ts` to use Zod for body validation. - Modified `acceptHostAppMinglar.ts` to implement Zod for request body validation. - Changed `assignAM.ts` to use Zod for request body validation. - Updated `editAgreementDetails.ts` to validate request body with Zod. - Refactored `getAllActivityOfHost.ts` to implement Zod for path and query parameter validation. - Changed `rejectHostApplication.ts` to use Zod for request body validation. - Updated `loginForMinglar.ts` to validate request body with Zod. - Refactored `registration.ts` to implement Zod for request body validation. - Modified `getAllCoadminAndAM.ts` to use Zod for query parameter validation. - Changed `getAllInvitationDetails.ts` to implement Zod for query parameter validation. - Updated `getAllInvitedCoadminAndAM.ts` to validate query parameters with Zod. - Refactored `inviteTeammate.ts` to use Zod for request body validation. - Modified `getBranchByBank.ts` to implement Zod for query parameter validation. - Changed `getCityByState.ts` to use Zod for query parameter validation.
78 lines
2.5 KiB
TypeScript
78 lines
2.5 KiB
TypeScript
import {
|
|
APIGatewayProxyEvent,
|
|
APIGatewayProxyResult,
|
|
Context,
|
|
} from 'aws-lambda';
|
|
import { safeHandler } from '../../../../../common/utils/handlers/safeHandler';
|
|
import { PrismaService } from '../../../../../common/database/prisma.service';
|
|
import { MinglarService } from '../../../services/minglar.service';
|
|
import ApiError from '../../../../../common/utils/helper/ApiError';
|
|
import { verifyOnlyMinglarAdminToken } from '../../../../../common/middlewares/jwt/authForOnlyMinglarAdmin';
|
|
import { sendAMEmailForHostAssign } from '../../../services/AMEmail.service';
|
|
import { parseBody } from '../../../../../common/utils/validation/validation.utils';
|
|
import { assignAmToHostSchema } from '../../../../../common/utils/validation/minglaradmin/hosthub.validation';
|
|
|
|
const prismaService = new PrismaService();
|
|
const minglarService = new MinglarService(prismaService);
|
|
|
|
/**
|
|
* Get all host applications handler
|
|
* Returns host details with status, submission date, and account manager info
|
|
*/
|
|
export const handler = safeHandler(
|
|
async (
|
|
event: APIGatewayProxyEvent,
|
|
context?: Context,
|
|
): Promise<APIGatewayProxyResult> => {
|
|
// Verify authentication token
|
|
const token =
|
|
event.headers['x-auth-token'] || event.headers['X-Auth-Token'];
|
|
if (!token) {
|
|
throw new ApiError(
|
|
401,
|
|
'This is a protected route. Please provide a valid token.',
|
|
);
|
|
}
|
|
|
|
// Verify token and get user info
|
|
const userInfo = await verifyOnlyMinglarAdminToken(token);
|
|
|
|
// Get user details including role
|
|
const user = await prismaService.user.findUnique({
|
|
where: { id: userInfo.id },
|
|
select: { id: true, roleXid: true },
|
|
});
|
|
|
|
if (!user) {
|
|
throw new ApiError(404, 'User not found');
|
|
}
|
|
|
|
// Parse and validate request body using Zod
|
|
const { hostXid: host_xid, accountManagerXid: account_manager_xid } = parseBody(
|
|
event.body,
|
|
assignAmToHostSchema
|
|
);
|
|
|
|
// Get all host applications from service based on user role
|
|
await minglarService.assignAMToHost(user.id, host_xid, account_manager_xid);
|
|
|
|
try {
|
|
await minglarService.notifyAMOfAssignment(account_manager_xid);
|
|
} catch (err) {
|
|
console.error('Failed to notify AM after assignment:', err);
|
|
}
|
|
|
|
return {
|
|
statusCode: 200,
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
'Access-Control-Allow-Origin': '*',
|
|
},
|
|
body: JSON.stringify({
|
|
success: true,
|
|
message: 'AM assigned to host successfully',
|
|
}),
|
|
};
|
|
},
|
|
);
|