From 3f921febe03b61b0da8863aec6e87a4e73ae1473 Mon Sep 17 00:00:00 2001 From: Mayank Mishra Date: Mon, 1 Dec 2025 20:25:23 +0530 Subject: [PATCH] Refactor host status determination logic in HostService to handle various submission cases, including updates and drafts. Update host suggestion review process to only mark suggestions as reviewed when not in draft state. --- src/modules/host/services/host.service.ts | 85 ++++++++++++++++------- 1 file changed, 61 insertions(+), 24 deletions(-) diff --git a/src/modules/host/services/host.service.ts b/src/modules/host/services/host.service.ts index eb9560a..d8ddb85 100644 --- a/src/modules/host/services/host.service.ts +++ b/src/modules/host/services/host.service.ts @@ -419,22 +419,58 @@ export class HostService { include: { hostParent: true }, }); + let hostStatusInternal; + let hostStatusDisplay; + let minglarStatusInternal; + let minglarStatusDisplay; + if (existingHostCompany) { + hostStatusInternal = existingHostCompany.hostStatusInternal; + hostStatusDisplay = existingHostCompany.hostStatusDisplay; + minglarStatusInternal = existingHostCompany.adminStatusInternal; + minglarStatusDisplay = existingHostCompany.adminStatusDisplay; + } + + // CASE 1: Host was asked to update AND is submitting final (NOT draft) + if (existingHostCompany.hostStatusInternal === HOST_STATUS_INTERNAL.HOST_TO_UPDATE && !isDraft) { + + hostStatusInternal = HOST_STATUS_INTERNAL.HOST_SUBMITTED; + hostStatusDisplay = HOST_STATUS_DISPLAY.UNDER_REVIEW; + + minglarStatusInternal = MINGLAR_STATUS_INTERNAL.AM_TO_REVIEW; + minglarStatusDisplay = MINGLAR_STATUS_DISPLAY.TO_REVIEW; + + } + // CASE 2: Host was asked to update BUT is saving as draft + else if (existingHostCompany.hostStatusInternal === HOST_STATUS_INTERNAL.HOST_TO_UPDATE && isDraft) { + + // DO NOT CHANGE ANY STATUS — KEEP ORIGINAL + hostStatusInternal = existingHostCompany.hostStatusInternal; + hostStatusDisplay = existingHostCompany.hostStatusDisplay; + minglarStatusInternal = existingHostCompany.adminStatusInternal; + minglarStatusDisplay = existingHostCompany.adminStatusDisplay; + + } + // CASE 3: Normal logic (new submission or regular update) + else { + + hostStatusInternal = isDraft + ? HOST_STATUS_INTERNAL.DRAFT + : HOST_STATUS_INTERNAL.HOST_SUBMITTED; + + hostStatusDisplay = isDraft + ? HOST_STATUS_DISPLAY.DRAFT + : HOST_STATUS_DISPLAY.UNDER_REVIEW; + + minglarStatusInternal = isDraft + ? MINGLAR_STATUS_INTERNAL.DRAFT + : MINGLAR_STATUS_INTERNAL.ADMIN_TO_REVIEW; + + minglarStatusDisplay = isDraft + ? MINGLAR_STATUS_DISPLAY.DRAFT + : MINGLAR_STATUS_DISPLAY.NEW; + } + // Determine status based on isDraft flag - const hostStatusInternal = isDraft - ? HOST_STATUS_INTERNAL.DRAFT - : HOST_STATUS_INTERNAL.HOST_SUBMITTED; - - const hostStatusDisplay = isDraft - ? HOST_STATUS_DISPLAY.DRAFT - : HOST_STATUS_DISPLAY.UNDER_REVIEW; - - const minglarStatusInternal = isDraft - ? MINGLAR_STATUS_INTERNAL.DRAFT - : MINGLAR_STATUS_INTERNAL.ADMIN_TO_REVIEW; - - const minglarStatusDisplay = isDraft - ? MINGLAR_STATUS_DISPLAY.DRAFT - : MINGLAR_STATUS_DISPLAY.NEW; const stepper = isDraft ? STEPPER.NOT_SUBMITTED : STEPPER.UNDER_REVIEW; @@ -750,15 +786,16 @@ export class HostService { trackStatus: hostDetails!.hostStatusInternal, }, }); - - await tx.hostSuggestion.updateMany({ - where: { hostXid: hostDetails.id, isActive: true, isreviewed: false }, - data: { - isreviewed: true, - reviewedByXid: user_xid, - reviewOn: new Date(), - }, - }) + if (!isDraft) { + await tx.hostSuggestion.updateMany({ + where: { hostXid: hostDetails.id, isActive: true, isreviewed: false }, + data: { + isreviewed: true, + reviewedByXid: user_xid, + reviewOn: new Date(), + }, + }) + } return updatedHost; });