From 926ea67e4107b465c4685c879bfb836e3c649577 Mon Sep 17 00:00:00 2001 From: Mayank Mishra Date: Fri, 21 Nov 2025 13:31:41 +0530 Subject: [PATCH] fixed code --- serverless.yml | 16 +++++++ src/modules/host/handlers/acceptAgreement.ts | 45 +++++++++++++++++++ src/modules/host/services/host.service.ts | 39 ++++++++++++---- src/modules/minglaradmin/dto/minglar.dto.ts | 6 +++ .../minglaradmin/handlers/loginForMinglar.ts | 7 ++- .../minglaradmin/services/minglar.service.ts | 4 +- 6 files changed, 102 insertions(+), 15 deletions(-) create mode 100644 src/modules/host/handlers/acceptAgreement.ts diff --git a/serverless.yml b/serverless.yml index 421b025..8d5b7d3 100644 --- a/serverless.yml +++ b/serverless.yml @@ -182,6 +182,22 @@ functions: path: /host/getById method: get + acceptMinglarAgreement: + handler: src/modules/host/handlers/acceptAgreement.handler + package: + patterns: + - 'src/modules/host/handlers/acceptAgreement.*' + - 'src/modules/host/services/**' + - 'common/**' + - 'src/common/**' + - 'node_modules/@prisma/client/**' + - 'node_modules/.prisma/**' + + events: + - httpApi: + path: /host/accept-agreement + method: patch + getStepperInfo: handler: src/modules/host/handlers/getStepper.handler package: diff --git a/src/modules/host/handlers/acceptAgreement.ts b/src/modules/host/handlers/acceptAgreement.ts new file mode 100644 index 0000000..109a4ee --- /dev/null +++ b/src/modules/host/handlers/acceptAgreement.ts @@ -0,0 +1,45 @@ +import { verifyHostToken } from '@/common/middlewares/jwt/authForHost'; +import { APIGatewayProxyEvent, APIGatewayProxyResult, Context } from 'aws-lambda'; +import { PrismaService } from '../../../common/database/prisma.service'; +import { safeHandler } from '../../../common/utils/handlers/safeHandler'; +import ApiError from '../../../common/utils/helper/ApiError'; +import { HostService } from '../services/host.service'; + +const prismaService = new PrismaService(); +const hostService = new HostService(prismaService); + +/** + * 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 verifyHostToken(token); + + + // Add suggestion using service + await hostService.acceptMinglarAgreement(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/host/services/host.service.ts b/src/modules/host/services/host.service.ts index 96645c0..dd34d92 100644 --- a/src/modules/host/services/host.service.ts +++ b/src/modules/host/services/host.service.ts @@ -179,16 +179,39 @@ export class HostService { return true; } - async addPaymentDetails(data: AddPaymentDetailsDTO): Promise { - const addedPaymentDetails = await this.prisma.hostBankDetails.create({ - data, - }); + async addPaymentDetails(data: AddPaymentDetailsDTO) { + return await this.prisma.$transaction(async (tx) => { + const addedPaymentDetails = await tx.hostBankDetails.create({ + data, + }); - if (!addedPaymentDetails) { - throw new ApiError(400, 'Failed to add payment details'); - } + if (!addedPaymentDetails) { + throw new ApiError(400, 'Failed to add payment details'); + } - return addedPaymentDetails; + await tx.hostHeader.update({ + where: { id: data.hostXid }, + data: { + stepper: STEPPER.BANK_DETAILS_UPDATED + } + }) + }) + } + + async acceptMinglarAgreement(user_xid: number) { + const hostDetails = await this.prisma.hostHeader.findFirst({ + where: { userXid: user_xid }, + select: { + id: true, + userXid: true, + } + }) + await this.prisma.hostHeader.update({ + where: { id: hostDetails.id }, + data: { + stepper: STEPPER.AGREEMENT_ACCEPTED + } + }) } async addOrUpdateCompanyDetails( diff --git a/src/modules/minglaradmin/dto/minglar.dto.ts b/src/modules/minglaradmin/dto/minglar.dto.ts index 35b75ec..21a9154 100644 --- a/src/modules/minglaradmin/dto/minglar.dto.ts +++ b/src/modules/minglaradmin/dto/minglar.dto.ts @@ -58,6 +58,9 @@ export class GetMinglarLoginResponseDTO { mobileNumber: string | null; isActive: boolean; roleXid: number; + isProfileUpdated: boolean; + profileImage: string; + userStatus: string; accessToken: string; refreshToken: string; @@ -69,6 +72,9 @@ export class GetMinglarLoginResponseDTO { this.mobileNumber = user.mobileNumber; this.isActive = user.isActive; this.roleXid = user.roleXid; + this.profileImage = user.profileImage; + this.isProfileUpdated = user.isProfileUpdated; + this.userStatus = user.userStatus; this.accessToken = accessToken; this.refreshToken = refreshToken; } diff --git a/src/modules/minglaradmin/handlers/loginForMinglar.ts b/src/modules/minglaradmin/handlers/loginForMinglar.ts index e890261..40393c6 100644 --- a/src/modules/minglaradmin/handlers/loginForMinglar.ts +++ b/src/modules/minglaradmin/handlers/loginForMinglar.ts @@ -1,11 +1,10 @@ import { APIGatewayProxyEvent, APIGatewayProxyResult, Context } from 'aws-lambda'; -import { safeHandler } from '../../../common/utils/handlers/safeHandler'; import { PrismaService } from '../../../common/database/prisma.service'; +import { safeHandler } from '../../../common/utils/handlers/safeHandler'; +import ApiError from '../../../common/utils/helper/ApiError'; +import { GetMinglarLoginResponseDTO } from '../dto/minglar.dto'; import { MinglarService } from '../services/minglar.service'; import { TokenService } from "../services/token.service"; -import { GetMinglarLoginResponseDTO } from '../dto/minglar.dto'; -import ApiError from '../../../common/utils/helper/ApiError'; -import * as bcrypt from 'bcryptjs'; const prismaService = new PrismaService(); const minglarSerivce = new MinglarService(prismaService); diff --git a/src/modules/minglaradmin/services/minglar.service.ts b/src/modules/minglaradmin/services/minglar.service.ts index 614304c..ab45421 100644 --- a/src/modules/minglaradmin/services/minglar.service.ts +++ b/src/modules/minglaradmin/services/minglar.service.ts @@ -131,7 +131,7 @@ export class MinglarService { async loginForMinglar(emailAddress: string, userPassword: string) { const existingUser = await this.prisma.user.findUnique({ - where: { emailAddress: emailAddress, isActive: true }, + where: { emailAddress: emailAddress, isActive: true, userStatus: USER_STATUS.ACTIVE } }); if (!existingUser) { @@ -539,8 +539,6 @@ export class MinglarService { inviteDetails: { some: { isMinglarInvitation: true, - is_accepted: true, - invitation_status: MINGLAR_INVITATION_STATUS.ACCEPTED, isActive: true } }