diff --git a/packages/server/src/common/config/app.ts b/packages/server/src/common/config/app.ts new file mode 100644 index 000000000..7a04a5481 --- /dev/null +++ b/packages/server/src/common/config/app.ts @@ -0,0 +1,5 @@ +import { registerAs } from '@nestjs/config'; + +export default registerAs('app', () => ({ + baseUrl: process.env.BASE_URL, +})); diff --git a/packages/server/src/common/config/index.ts b/packages/server/src/common/config/index.ts index 607858638..fec0d23c6 100644 --- a/packages/server/src/common/config/index.ts +++ b/packages/server/src/common/config/index.ts @@ -1,3 +1,4 @@ +import app from './app'; import systemDatabase from './system-database'; import tenantDatabase from './tenant-database'; import signup from './signup'; @@ -18,6 +19,7 @@ import throttle from './throttle'; import cloud from './cloud'; export const config = [ + app, systemDatabase, cloud, tenantDatabase, diff --git a/packages/server/src/modules/SaleInvoices/commands/GenerateInvoicePaymentLink.service.ts b/packages/server/src/modules/SaleInvoices/commands/GenerateInvoicePaymentLink.service.ts index 2a181d6d7..7b6662842 100644 --- a/packages/server/src/modules/SaleInvoices/commands/GenerateInvoicePaymentLink.service.ts +++ b/packages/server/src/modules/SaleInvoices/commands/GenerateInvoicePaymentLink.service.ts @@ -10,6 +10,7 @@ import { PaymentLink } from '@/modules/PaymentLinks/models/PaymentLink'; import { SaleInvoice } from '../models/SaleInvoice'; import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel'; import { TenancyContext } from '@/modules/Tenancy/TenancyContext.service'; +import { ConfigService } from '@nestjs/config'; @Injectable() export class GenerateShareLink { @@ -18,13 +19,14 @@ export class GenerateShareLink { private eventPublisher: EventEmitter2, private transformer: TransformerInjectable, private tenancyContext: TenancyContext, + private configService: ConfigService, @Inject(SaleInvoice.name) private saleInvoiceModel: TenantModelProxy, @Inject(PaymentLink.name) private paymentLinkModel: typeof PaymentLink, - ) {} + ) { } /** * Generates private or public payment link for the given sale invoice. @@ -75,6 +77,9 @@ export class GenerateShareLink { return this.transformer.transform( paymentLink, new GeneratePaymentLinkTransformer(), + { + baseUrl: this.configService.get('app.baseUrl'), + } ); }); } diff --git a/packages/server/src/modules/SaleInvoices/commands/GeneratePaymentLink.transformer.ts b/packages/server/src/modules/SaleInvoices/commands/GeneratePaymentLink.transformer.ts index 66aaa974d..14d2800b4 100644 --- a/packages/server/src/modules/SaleInvoices/commands/GeneratePaymentLink.transformer.ts +++ b/packages/server/src/modules/SaleInvoices/commands/GeneratePaymentLink.transformer.ts @@ -1,7 +1,10 @@ import { Transformer } from '@/modules/Transformer/Transformer'; import { PUBLIC_PAYMENT_LINK } from '../constants'; -export class GeneratePaymentLinkTransformer extends Transformer { +interface GeneratePaymentLinkTransformerOptions { + baseUrl: string; +} +export class GeneratePaymentLinkTransformer extends Transformer { /** * Exclude these attributes from payment link object. * @returns {Array} @@ -23,6 +26,9 @@ export class GeneratePaymentLinkTransformer extends Transformer { * @returns {string} */ public link(link) { - return PUBLIC_PAYMENT_LINK?.replace('{PAYMENT_LINK_ID}', link.linkId); + return PUBLIC_PAYMENT_LINK?.replace( + '{BASE_URL}', + this.options.baseUrl, + ).replace('{PAYMENT_LINK_ID}', link.linkId); } } diff --git a/packages/server/src/modules/SaleInvoices/constants.ts b/packages/server/src/modules/SaleInvoices/constants.ts index 9c889a49f..6ab883cff 100644 --- a/packages/server/src/modules/SaleInvoices/constants.ts +++ b/packages/server/src/modules/SaleInvoices/constants.ts @@ -3,10 +3,9 @@ export const SendSaleInvoiceQueue = 'SendSaleInvoiceQueue'; export const SendSaleInvoiceMailJob = 'SendSaleInvoiceMailJob'; -const BASE_URL = 'http://localhost:3000'; export const DEFAULT_INVOICE_MAIL_SUBJECT = - 'Invoice {Invoice Number} from {Company Name} for {Customer Name}'; +'Invoice {Invoice Number} from {Company Name} for {Customer Name}'; export const DEFAULT_INVOICE_MAIL_CONTENT = `Hi {Customer Name}, Here's invoice # {Invoice Number} for {Invoice Amount} @@ -23,8 +22,8 @@ Thanks, export const DEFAULT_INVOICE_REMINDER_MAIL_SUBJECT = 'Invoice {InvoiceNumber} reminder from {CompanyName}'; -export const DEFAULT_INVOICE_REMINDER_MAIL_CONTENT = ` -

Dear {CustomerName}

+ export const DEFAULT_INVOICE_REMINDER_MAIL_CONTENT = ` +

Dear {CustomerName}

You might have missed the payment date and the invoice is now overdue by {OverdueDays} days.

Invoice #{InvoiceNumber}
Due Date : {InvoiceDueDate}
@@ -36,7 +35,7 @@ Amount : {InvoiceAmount}

`; -export const PUBLIC_PAYMENT_LINK = `${BASE_URL}/payment/{PAYMENT_LINK_ID}`; +export const PUBLIC_PAYMENT_LINK = "{BASE_URL}/payment/{PAYMENT_LINK_ID}"; export const ERRORS = { INVOICE_NUMBER_NOT_UNIQUE: 'INVOICE_NUMBER_NOT_UNIQUE',