diff --git a/serverless.yml b/serverless.yml index 9311ae4..55667af 100644 --- a/serverless.yml +++ b/serverless.yml @@ -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: diff --git a/src/modules/minglaradmin/handlers/acceptHostApplication.ts b/src/modules/minglaradmin/handlers/acceptHostApplication.ts index 61a912e..a903f16 100644 --- a/src/modules/minglaradmin/handlers/acceptHostApplication.ts +++ b/src/modules/minglaradmin/handlers/acceptHostApplication.ts @@ -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, diff --git a/src/modules/minglaradmin/handlers/inviteTeammate.ts b/src/modules/minglaradmin/handlers/inviteTeammate.ts index ea523cd..efefedc 100644 --- a/src/modules/minglaradmin/handlers/inviteTeammate.ts +++ b/src/modules/minglaradmin/handlers/inviteTeammate.ts @@ -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); diff --git a/src/modules/minglaradmin/handlers/rejectHostApplication.ts b/src/modules/minglaradmin/handlers/rejectHostApplication.ts new file mode 100644 index 0000000..3e2e189 --- /dev/null +++ b/src/modules/minglaradmin/handlers/rejectHostApplication.ts @@ -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 => { + // 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, + }), + }; +}); diff --git a/src/modules/minglaradmin/services/minglar.service.ts b/src/modules/minglaradmin/services/minglar.service.ts index 99c8655..614304c 100644 --- a/src/modules/minglaradmin/services/minglar.service.ts +++ b/src/modules/minglaradmin/services/minglar.service.ts @@ -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 + } + }) + }) + } + }