65 lines
2.1 KiB
TypeScript
65 lines
2.1 KiB
TypeScript
import { verifyMinglarAdminToken } from '../../../../../common/middlewares/jwt/authForMinglarAdmin';
|
|
import { APIGatewayProxyEvent, APIGatewayProxyResult, Context } from 'aws-lambda';
|
|
import { prismaClient } from '../../../../../common/database/prisma.lambda.service';
|
|
import { safeHandler } from '../../../../../common/utils/handlers/safeHandler';
|
|
import ApiError from '../../../../../common/utils/helper/ApiError';
|
|
import { MinglarService } from '../../../services/minglar.service';
|
|
import { sendAMRejectionMailtoHost } from '../../../services/rejectionMailtoHost.service';
|
|
|
|
const minglarService = new MinglarService(prismaClient);
|
|
|
|
interface AddSuggestionBody {
|
|
hostXid: number;
|
|
title: string;
|
|
comments: string;
|
|
}
|
|
|
|
/**
|
|
* Add suggestion handler for host applications
|
|
* Allows Minglar Admin, Co_Admin, and Account Manager to add suggestions
|
|
* Types: Setup Profile, Review Account, Add Payment Details, Agreement
|
|
*/
|
|
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 verifyMinglarAdminToken(token);
|
|
|
|
// Parse request body
|
|
let body: AddSuggestionBody;
|
|
|
|
try {
|
|
body = event.body ? JSON.parse(event.body) : {};
|
|
} catch (error) {
|
|
throw new ApiError(400, 'Invalid JSON in request body');
|
|
}
|
|
|
|
const { hostXid } = body;
|
|
|
|
|
|
// Add suggestion using service
|
|
await minglarService.rejectHostApplicationAM(hostXid, userInfo.id);
|
|
const hostDetails = await minglarService.getUserDetails(hostXid)
|
|
await sendAMRejectionMailtoHost(hostDetails.emailAddress)
|
|
|
|
return {
|
|
statusCode: 200,
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
'Access-Control-Allow-Origin': '*',
|
|
},
|
|
body: JSON.stringify({
|
|
success: true,
|
|
message: 'Application rejected successfully',
|
|
data: null,
|
|
}),
|
|
};
|
|
});
|