From 9e158d4e8d2cc40375ddb094b6a3381c2c526e84 Mon Sep 17 00:00:00 2001 From: SepehrYahyaee <7heycallmegray@gmail.com> Date: Sat, 31 Oct 2026 11:08:04 +0330 Subject: [PATCH] fix: support user panel base path in SMS links --- .env.example | 3 ++ .../request-management.service.ts | 13 +++++++-- .../sms-orchestration.service.ts | 29 +++++++++++++++++-- 3 files changed, 39 insertions(+), 6 deletions(-) diff --git a/.env.example b/.env.example index 33b653e..2f7def0 100644 --- a/.env.example +++ b/.env.example @@ -13,6 +13,9 @@ CLAIM_V2_TOTAL_PAYMENT_CAP_TOMAN=53000000 # 🌐 Application URLs # --------------------------------------------- URL = +# Optional path where the user panel is mounted behind the public URL. +# Example: URL=https://chatr.parsianinsurance.com/car-damage and USER_BASE_PATH=user +# produces SMS links under https://chatr.parsianinsurance.com/car-damage/user/v1/... USER_BASE_PATH = BASE_URL_DEV = diff --git a/src/request-management/request-management.service.ts b/src/request-management/request-management.service.ts index 637164d..7e79213 100644 --- a/src/request-management/request-management.service.ts +++ b/src/request-management/request-management.service.ts @@ -2885,19 +2885,26 @@ export class RequestManagementService { ?.phoneNumber; const secondPhone = (req.parties?.[secondIdx]?.person as any) ?.phoneNumber; - const baseUrl = process.env.URL; const token = String(req._id); const targets = [ firstPhone ? { receptor: firstPhone, - link: `${baseUrl}/user?token=${token}`, + link: this.smsOrchestrationService.buildBlamePartyLink( + token, + "FIRST", + "v1", + ), } : null, secondPhone ? { receptor: secondPhone, - link: `${baseUrl}/user2?token=${token}`, + link: this.smsOrchestrationService.buildBlamePartyLink( + token, + "SECOND", + "v1", + ), } : null, ].filter( diff --git a/src/sms-orchestration/sms-orchestration.service.ts b/src/sms-orchestration/sms-orchestration.service.ts index 6138675..466ed75 100644 --- a/src/sms-orchestration/sms-orchestration.service.ts +++ b/src/sms-orchestration/sms-orchestration.service.ts @@ -38,12 +38,35 @@ export class SmsOrchestrationService implements OnModuleInit { ); } + /** + * `URL` is the public application/API base (and is also used for file URLs). + * Some deployments mount the user panel below a separate reverse-proxy path, + * e.g. `/car-damage/user`; keep that panel-only segment out of `URL`. + */ + private userPanelBaseUrl(): string { + const applicationUrl = String(process.env.URL ?? "") + .trim() + .replace(/\/+$/, ""); + const userBasePath = String(process.env.USER_BASE_PATH ?? "") + .trim() + .replace(/^\/+|\/+$/g, ""); + return userBasePath ? `${applicationUrl}/${userBasePath}` : applicationUrl; + } + + private buildUserPanelLink(...segments: string[]): string { + const path = segments + .map((segment) => String(segment).replace(/^\/+|\/+$/g, "")) + .filter(Boolean) + .join("/"); + return `${this.userPanelBaseUrl()}/${path}`; + } + buildInviteLink( frontendRoute: string, requestId: string, versionPrefix: string, ): string { - return `${process.env.URL}/${versionPrefix}/${frontendRoute}?token=${requestId}`; + return `${this.buildUserPanelLink(versionPrefix, frontendRoute)}?token=${requestId}`; } buildBlamePartyLink( @@ -52,11 +75,11 @@ export class SmsOrchestrationService implements OnModuleInit { versionPrefix: string, ): string { const route = partyRole === "SECOND" ? "user2" : "user"; - return `${process.env.URL}/${versionPrefix}/${route}?token=${requestId}`; + return `${this.buildUserPanelLink(versionPrefix, route)}?token=${requestId}`; } buildClaimLink(claimRequestId: string, versionPrefix: string): string { - return `${process.env.URL}/${versionPrefix}/caseClaim?token=${claimRequestId}`; + return `${this.buildUserPanelLink(versionPrefix, "caseClaim")}?token=${claimRequestId}`; } async sendInviteLink(