made accept host application and reject host application apis

This commit is contained in:
2025-11-21 12:27:23 +05:30
parent e366bb4a70
commit 8f25bb87e6
5 changed files with 120 additions and 19 deletions

View File

@@ -412,6 +412,22 @@ functions:
path: /minglaradmin/assign-am-to-host
method: patch
editAgreementDetails:
handler: src/modules/minglaradmin/handlers/editAgreementDetails.handler
package:
patterns:
- 'src/modules/minglaradmin/**'
- 'common/**'
- 'src/common/**'
- 'node_modules/@prisma/client/**'
- 'node_modules/.prisma/**'
events:
- httpApi:
path: /minglaradmin/edit-agreement-details
method: patch
editAgreementDetails:
handler: src/modules/minglaradmin/handlers/editAgreementDetails.handler
package:

View File

@@ -32,16 +32,6 @@ export const handler = safeHandler(async (
// Verify token and get user info
const userInfo = await verifyMinglarAdminToken(token);
// Get user details
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 request body
let body: AddSuggestionBody;
@@ -55,7 +45,7 @@ export const handler = safeHandler(async (
// Add suggestion using service
await minglarService.acceptHostApplication(hostXid, user.id);
await minglarService.acceptHostApplication(hostXid, userInfo.id);
return {
statusCode: 200,

View File

@@ -78,14 +78,14 @@ export const handler = safeHandler(async (
throw new ApiError(400, 'Per value must be greater than 0');
}
// Use single service method that encapsulates the transaction
await minglarService.inviteTeammate(
emailAddress,
roleXid,
isFixedSalary,
perValue || 0,
userInfo.id
);
// Use single service method that encapsulates the transaction
await minglarService.inviteTeammate(
emailAddress,
roleXid,
isFixedSalary,
perValue || 0,
userInfo.id
);
// send email after transaction commits
await sendInvitationEmailForMinglarAdmin(emailAddress);

View File

@@ -0,0 +1,62 @@
import { APIGatewayProxyEvent, APIGatewayProxyResult, Context } from 'aws-lambda';
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 { MinglarService } from '../services/minglar.service';
const prismaService = new PrismaService();
const minglarService = new MinglarService(prismaService);
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.rejectHostApplication(hostXid, userInfo.id);
return {
statusCode: 200,
headers: {
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': '*',
},
body: JSON.stringify({
success: true,
message: 'Application accepted successfully',
data: null,
}),
};
});

View File

@@ -734,6 +734,39 @@ export class MinglarService {
})
}
async rejectHostApplication(host_xid: number, user_xid: number) {
await this.prisma.$transaction(async (tx) => {
const hostDetails = await tx.hostHeader.findFirst({
where: { id: host_xid },
select: { id: true, userXid: true }
})
if (!hostDetails) {
throw new Error("Host not found");
}
await tx.hostHeader.update({
where: {
id: host_xid,
hostStatusInternal: HOST_STATUS_INTERNAL.HOST_SUBMITTED,
hostStatusDisplay: HOST_STATUS_DISPLAY.UNDER_REVIEW
},
data: {
hostStatusInternal: HOST_STATUS_INTERNAL.REJECTED,
hostStatusDisplay: HOST_STATUS_DISPLAY.REJECTED,
adminStatusInternal: MINGLAR_STATUS_INTERNAL.ADMIN_REJECTED,
adminStatusDisplay: MINGLAR_STATUS_DISPLAY.REJECTED,
}
})
await tx.user.update({
where: { id: hostDetails.userXid },
data: {
userStatus: USER_STATUS.REJECTED
}
})
})
}
}