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; });