diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 4bb645c..e33cac8 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -784,7 +784,6 @@ model HostParent { countries Countries? @relation(fields: [countryXid], references: [id], onDelete: Restrict) pinCode String? @map("pin_code") @db.VarChar(30) logoPath String? @map("logo_path") @db.VarChar(400) - isSubsidairy Boolean @default(false) @map("is_subsidairy") registrationNumber String? @map("registration_number") @db.VarChar(30) panNumber String? @map("pan_number") @db.VarChar(30) gstNumber String? @map("gst_number") @db.VarChar(30) diff --git a/serverless/functions/minglaradmin.yml b/serverless/functions/minglaradmin.yml index 2e06928..bed9504 100644 --- a/serverless/functions/minglaradmin.yml +++ b/serverless/functions/minglaradmin.yml @@ -1,8 +1,6 @@ # Minglar Admin Module Functions # Admin dashboard and management endpoints - - minglarRegistration: handler: src/modules/minglaradmin/handlers/registration.handler memorySize: 384 @@ -96,7 +94,6 @@ prepopulateRole: path: /minglaradmin/prepopulate-Roles method: get - getHostDetailsById: handler: src/modules/minglaradmin/handlers/hosthub/hosts/getByIdHostDetails.handler memorySize: 384 @@ -283,8 +280,8 @@ assignAMToHost: path: /minglaradmin/hosthub/onboarding/assign-am method: patch -editAgreementDetails: - handler: src/modules/minglaradmin/handlers/hosthub/onboarding/editAgreementDetails.handler +editAgreementDetailsAndAccept: + handler: src/modules/minglaradmin/handlers/hosthub/onboarding/editAgreementDetailsAndAccept.handler memorySize: 384 package: patterns: @@ -296,7 +293,7 @@ editAgreementDetails: - ${file(./serverless/patterns/base.yml):pattern4} events: - httpApi: - path: /minglaradmin/hosthub/onboarding/edit-agreement + path: /minglaradmin/hosthub/onboarding/edit-agreement-accept-host method: patch acceptHostApplication: @@ -331,22 +328,6 @@ RejectPQQByAM: path: /minglaradmin/hosthub/hosts/reject-pqq-by-am method: patch -acceptHostApplicationMinglar: - handler: src/modules/minglaradmin/handlers/hosthub/onboarding/acceptHostAppMinglar.handler - memorySize: 384 - package: - patterns: - - 'src/modules/minglaradmin/handlers/hosthub/onboarding/**' - - 'src/modules/minglaradmin/services/**' - - ${file(./serverless/patterns/base.yml):pattern1} - - ${file(./serverless/patterns/base.yml):pattern2} - - ${file(./serverless/patterns/base.yml):pattern3} - - ${file(./serverless/patterns/base.yml):pattern4} - events: - - httpApi: - path: /minglaradmin/hosthub/onboarding/accept-host-application-minglar - method: patch - rejectHostApplication: handler: src/modules/minglaradmin/handlers/hosthub/onboarding/rejectHostApplication.handler memorySize: 384 diff --git a/src/modules/host/handlers/Host_Admin/onboarding/submitCompanyDetails.ts b/src/modules/host/handlers/Host_Admin/onboarding/submitCompanyDetails.ts index 265ed07..c35ba17 100644 --- a/src/modules/host/handlers/Host_Admin/onboarding/submitCompanyDetails.ts +++ b/src/modules/host/handlers/Host_Admin/onboarding/submitCompanyDetails.ts @@ -178,13 +178,8 @@ export const handler = safeHandler(async (event: APIGatewayProxyEvent): Promise< const file = files.find((f) => f.fieldName === doc.fieldName); // In DRAFT mode → allow missing documents - if (isDraft && !file) { - return { ...doc, file: null }; - } - - // In FINAL mode → file must exist if (!file) { - throw new ApiError(400, `File not found for field: ${doc.fieldName}`); + return { ...doc, file: null }; } return { ...doc, file }; @@ -249,7 +244,7 @@ export const handler = safeHandler(async (event: APIGatewayProxyEvent): Promise< /** Upload host docs */ const uploadedHostDocs: Array = []; for (const doc of hostDocs) { - if (isDraft && !doc.file) continue; + if (!doc.file) continue; const path = await uploadToS3( doc.file.buffer, @@ -270,7 +265,7 @@ export const handler = safeHandler(async (event: APIGatewayProxyEvent): Promise< /** Upload parent docs */ const uploadedParentDocs: Array = []; for (const doc of parentDocs) { - if (!doc.file && isDraft) continue; // skip missing files in draft mode + if (!doc.file) continue; // skip missing files in draft mode const path = await uploadToS3( doc.file.buffer, diff --git a/src/modules/host/handlers/getStepper.ts b/src/modules/host/handlers/getStepper.ts index aaaca8f..fae6b65 100644 --- a/src/modules/host/handlers/getStepper.ts +++ b/src/modules/host/handlers/getStepper.ts @@ -26,7 +26,7 @@ export const handler = safeHandler(async ( } // Fetch user with their HostHeader stepper info - const host = await hostService.getHostById(userId); + const host = await hostService.getHostIdByUserXid(userId); if (!host) { throw new ApiError(404, 'Host record not found'); diff --git a/src/modules/host/services/host.service.ts b/src/modules/host/services/host.service.ts index 1a577e4..29b3cc3 100644 --- a/src/modules/host/services/host.service.ts +++ b/src/modules/host/services/host.service.ts @@ -498,7 +498,6 @@ export class HostService { : undefined, pinCode: parentCompanyData.pinCode || null, logoPath: parentCompanyData.logoPath || null, - isSubsidairy: false, registrationNumber: parentCompanyData.registrationNumber || null, panNumber: parentCompanyData.panNumber || null, gstNumber: parentCompanyData.gstNumber || null, @@ -617,7 +616,6 @@ export class HostService { : undefined, pinCode: parentCompanyData.pinCode || null, logoPath: parentCompanyData.logoPath || null, - isSubsidairy: false, registrationNumber: parentCompanyData.registrationNumber || null, panNumber: parentCompanyData.panNumber || null, gstNumber: parentCompanyData.gstNumber || null, @@ -741,6 +739,15 @@ export class HostService { }, }); + await tx.hostSuggestion.updateMany({ + where: { hostXid: hostDetails.id, isActive: true, isreviewed: false }, + data: { + isreviewed: true, + reviewedByXid: user_xid, + reviewOn: new Date(), + }, + }) + return updatedHost; }); } diff --git a/src/modules/minglaradmin/handlers/hosthub/hosts/addSuggestion.ts b/src/modules/minglaradmin/handlers/hosthub/hosts/addSuggestion.ts index 0e03366..777dd37 100644 --- a/src/modules/minglaradmin/handlers/hosthub/hosts/addSuggestion.ts +++ b/src/modules/minglaradmin/handlers/hosthub/hosts/addSuggestion.ts @@ -13,6 +13,7 @@ interface AddSuggestionBody { hostXid: number; title: string; comments: string; + isParent: boolean; } /** @@ -52,7 +53,7 @@ export const handler = safeHandler(async ( throw new ApiError(400, 'Invalid JSON in request body'); } - const { hostXid, title, comments } = body; + const { hostXid, title, comments, isParent } = body; // Validate required fields if (!hostXid) { @@ -74,7 +75,7 @@ export const handler = safeHandler(async ( } // Add suggestion using service - await minglarService.addHostSuggestion(hostXid, title, comments, user.id); + await minglarService.addHostSuggestion(hostXid, title, comments, user.id, isParent); return { statusCode: 200, diff --git a/src/modules/minglaradmin/handlers/hosthub/onboarding/acceptHostAppMinglar.ts b/src/modules/minglaradmin/handlers/hosthub/onboarding/acceptHostAppMinglar.ts deleted file mode 100644 index ff149f2..0000000 --- a/src/modules/minglaradmin/handlers/hosthub/onboarding/acceptHostAppMinglar.ts +++ /dev/null @@ -1,68 +0,0 @@ -import { verifyOnlyMinglarAdminToken } from '../../../../../common/middlewares/jwt/authForOnlyMinglarAdmin'; -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 { sendEmailToHostForMinglarApproval } from '../../../services/approvalMailtoHost.service'; -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 verifyOnlyMinglarAdminToken(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.acceptHostApplicationMinglarAdmin(hostXid, userInfo.id); - const hostDetails = await minglarService.getUserDetails(userInfo.id) - if (!hostDetails?.emailAddress) { - throw new ApiError(404, 'Host details or email address not found'); - } - await sendEmailToHostForMinglarApproval(hostDetails.emailAddress) - - 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/handlers/hosthub/onboarding/editAgreementDetails.ts b/src/modules/minglaradmin/handlers/hosthub/onboarding/editAgreementDetailsAndAccept.ts similarity index 93% rename from src/modules/minglaradmin/handlers/hosthub/onboarding/editAgreementDetails.ts rename to src/modules/minglaradmin/handlers/hosthub/onboarding/editAgreementDetailsAndAccept.ts index 83a6db8..fb24e33 100644 --- a/src/modules/minglaradmin/handlers/hosthub/onboarding/editAgreementDetails.ts +++ b/src/modules/minglaradmin/handlers/hosthub/onboarding/editAgreementDetailsAndAccept.ts @@ -64,8 +64,9 @@ export const handler = safeHandler(async ( payoutDurationFrequency } = body; - await minglarService.editAgreementDetails( + await minglarService.acceptHostApplicationMinglarAdmin( host_xid, + userInfo.id, agreementStartDate, duration, isCommisionBase, @@ -73,8 +74,8 @@ export const handler = safeHandler(async ( amountPerBooking, durationFrequency, payoutDurationNum, - payoutDurationFrequency - ); + payoutDurationFrequency); + // await sendEmailToHostForMinglarApproval(hostDetails.emailAddress) return { statusCode: 200, diff --git a/src/modules/minglaradmin/services/minglar.service.ts b/src/modules/minglaradmin/services/minglar.service.ts index e107fa0..9955875 100644 --- a/src/modules/minglaradmin/services/minglar.service.ts +++ b/src/modules/minglaradmin/services/minglar.service.ts @@ -743,9 +743,9 @@ export class MinglarService { /** APPLICATION STATUS FILTER (NEW) **/ const APPLICATION_STATUS_MAP: Record = { - "Admin To Review": MINGLAR_STATUS_INTERNAL.ADMIN_TO_REVIEW, - "AM To Review": MINGLAR_STATUS_INTERNAL.AM_TO_REVIEW, - "AM Rejected": MINGLAR_STATUS_INTERNAL.AM_REJECTED, + "New": MINGLAR_STATUS_INTERNAL.AM_TO_REVIEW && MINGLAR_STATUS_DISPLAY.NEW, + "To_Review": MINGLAR_STATUS_INTERNAL.AM_TO_REVIEW && MINGLAR_STATUS_DISPLAY.TO_REVIEW, + "Enchancing": MINGLAR_STATUS_INTERNAL.AM_REJECTED, }; if (applicationStatus?.trim()) { @@ -1214,8 +1214,7 @@ export class MinglarService { if ( hostDetails.adminStatusInternal !== - MINGLAR_STATUS_INTERNAL.AM_NOT_ASSIGNED && - hostDetails.adminStatusDisplay !== MINGLAR_STATUS_DISPLAY.AM_NOT_ASSIGNED + MINGLAR_STATUS_INTERNAL.AM_NOT_ASSIGNED ) { throw new ApiError(400, 'Invalid host status'); } @@ -1267,6 +1266,7 @@ export class MinglarService { title: string, comments: string, reviewedByXid: number, + isParent: boolean = false, ) { // Check if host exists const hostHeader = await this.prisma.hostHeader.findUnique({ @@ -1285,7 +1285,7 @@ export class MinglarService { hostXid: hostXid, title: title, comments: comments, - isparent: false, + isparent: isParent, isreviewed: false, reviewedByXid: reviewedByXid, reviewOn: null, @@ -1350,41 +1350,13 @@ export class MinglarService { return suggestions; } - async editAgreementDetails( - host_xid: number, - agreementStartDate: string, - duration: number, - isCommisionBase: boolean, - commisionPer: number, - amountPerBooking: number, - durationFrequency: string, - payoutDurationNum: number, - payoutDurationFrequency: string, - ) { - return await this.prisma.hostHeader.update({ - where: { id: host_xid }, - data: { - durationNumber: Number(duration), - durationFrequency: durationFrequency, - agreementStartDate: new Date(agreementStartDate), - isCommisionBase: isCommisionBase, - commisionPer: commisionPer ? Number(commisionPer) : null, // Convert to number if exists - amountPerBooking: amountPerBooking ? Number(amountPerBooking) : null, // Convert to number if exists - payoutDurationNum: Number(payoutDurationNum), // Convert to number - payoutDurationFrequency: payoutDurationFrequency, - }, - }); - } - async acceptHostApplication(host_xid: number, user_xid: number) { return await this.prisma.$transaction(async (tx) => { await this.prisma.hostHeader.update({ where: { id: host_xid, hostStatusInternal: HOST_STATUS_INTERNAL.HOST_SUBMITTED, - hostStatusDisplay: HOST_STATUS_DISPLAY.UNDER_REVIEW, adminStatusInternal: MINGLAR_STATUS_INTERNAL.AM_TO_REVIEW, - adminStatusDisplay: MINGLAR_STATUS_DISPLAY.TO_REVIEW, }, data: { hostStatusInternal: HOST_STATUS_INTERNAL.APPROVED, @@ -1406,17 +1378,33 @@ export class MinglarService { }); } - async acceptHostApplicationMinglarAdmin(host_xid: number, user_xid: number) { + async acceptHostApplicationMinglarAdmin( + host_xid: number, + user_xid: number, + agreementStartDate: string, + duration: number, + isCommisionBase: boolean, + commisionPer: number, + amountPerBooking: number, + durationFrequency: string, + payoutDurationNum: number, + payoutDurationFrequency: string,) { return await this.prisma.$transaction(async (tx) => { - await tx.hostHeader.update({ + await this.prisma.hostHeader.update({ where: { id: host_xid, hostStatusInternal: HOST_STATUS_INTERNAL.HOST_SUBMITTED, - hostStatusDisplay: HOST_STATUS_DISPLAY.UNDER_REVIEW, adminStatusInternal: MINGLAR_STATUS_INTERNAL.ADMIN_TO_REVIEW, - adminStatusDisplay: MINGLAR_STATUS_DISPLAY.NEW, }, data: { + durationNumber: Number(duration), + durationFrequency: durationFrequency, + agreementStartDate: new Date(agreementStartDate), + isCommisionBase: isCommisionBase, + commisionPer: commisionPer ? Number(commisionPer) : null, // Convert to number if exists + amountPerBooking: amountPerBooking ? Number(amountPerBooking) : null, // Convert to number if exists + payoutDurationNum: Number(payoutDurationNum), // Convert to number + payoutDurationFrequency: payoutDurationFrequency, isApproved: true, hostStatusInternal: HOST_STATUS_INTERNAL.HOST_SUBMITTED, hostStatusDisplay: HOST_STATUS_DISPLAY.UNDER_REVIEW, @@ -1606,6 +1594,12 @@ export class MinglarService { const host = await this.prisma.hostHeader.findFirst({ where: { id: host_xid }, include: { + companyTypes: { + select: { + id: true, + companyTypeName: true, + }, + }, hostParent: { include: { HostParenetDocuments: { @@ -1616,7 +1610,13 @@ export class MinglarService { documentTypeXid: true, documentType: true } - } + }, + companyTypes: { + select: { + id: true, + companyTypeName: true, + }, + }, } }, HostBankDetails: true, @@ -1625,12 +1625,6 @@ export class MinglarService { documentType: true, }, }, - companyTypes: { - select: { - id: true, - companyTypeName: true, - }, - }, user: { select: { id: true,