From 49a9f0c2899139f0743132af75ec7379f0cd4909 Mon Sep 17 00:00:00 2001 From: Alireza Hassani Date: Tue, 11 Aug 2026 15:46:18 +0330 Subject: [PATCH] Expose invoice locale on public payloads and accept English name fields on create customer. Public invoices need branding defaultLocale for RTL viewers; customer create aligns with the business add-customer form. Co-authored-by: Cursor --- src/customers/customers.service.ts | 2 ++ src/customers/dto/create-customer.dto.ts | 10 ++++++++++ src/invoices/invoices.service.ts | 19 ++++++++++++++++++- 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/customers/customers.service.ts b/src/customers/customers.service.ts index d1380a5..4c6f044 100644 --- a/src/customers/customers.service.ts +++ b/src/customers/customers.service.ts @@ -286,6 +286,8 @@ export class CustomersService { email: dto.email, firstName: dto.firstName, lastName: dto.lastName, + firstNameEn: dto.firstNameEn?.trim() || null, + lastNameEn: dto.lastNameEn?.trim() || null, cellVerifiedAt: new Date(), }, })); diff --git a/src/customers/dto/create-customer.dto.ts b/src/customers/dto/create-customer.dto.ts index 2571794..0e1adb5 100644 --- a/src/customers/dto/create-customer.dto.ts +++ b/src/customers/dto/create-customer.dto.ts @@ -26,6 +26,16 @@ export class CreateCustomerDto { @MinLength(2) lastName!: string; + @IsOptional() + @IsString() + @MinLength(2) + firstNameEn?: string; + + @IsOptional() + @IsString() + @MinLength(2) + lastNameEn?: string; + @IsOptional() @IsEmail() email?: string; diff --git a/src/invoices/invoices.service.ts b/src/invoices/invoices.service.ts index b21c3c6..2e4fc4e 100644 --- a/src/invoices/invoices.service.ts +++ b/src/invoices/invoices.service.ts @@ -23,6 +23,8 @@ import { UpdateInvoiceStatusDto, UpdateInvoiceTemplateDto, } from './dto/invoice.dto'; +import { normalizeBusinessSettings } from '../business-settings/business-settings.util'; +import type { DashboardLocale } from '../business-settings/business-settings.types'; /** 12-digit unguessable public link token (not the sequential PK). */ const PUBLIC_ID_MIN = 100_000_000_000; @@ -214,6 +216,7 @@ export class InvoicesService { id: true, name: true, nameFa: true, + settings: true, domains: { where: { isActive: true }, orderBy: [{ isPrimary: 'desc' as const }, { createdAt: 'asc' as const }], @@ -427,6 +430,7 @@ export class InvoicesService { id: bigint; name: string; nameFa: string | null; + settings?: Prisma.JsonValue; domains?: Array<{ host: string }>; }; issuer?: { id: bigint; firstName: string | null; lastName: string | null } | null; @@ -1244,13 +1248,26 @@ export class InvoicesService { /** Public payload: no internal notes / issuer / sequential id / user contact info. */ private toPublicInvoicePayload(row: Parameters[0]) { const serialized = this.serializeInvoice(row, true); + const locale: DashboardLocale = normalizeBusinessSettings( + row.business && 'settings' in row.business ? row.business.settings : null, + ).branding.defaultLocale; + return { publicId: serialized.publicId, status: serialized.status, name: serialized.name, topText: serialized.topText, issuedAt: serialized.issuedAt, - business: serialized.business, + locale, + business: serialized.business + ? { + ...serialized.business, + displayName: + locale === 'fa' && serialized.business.nameFa?.trim() + ? serialized.business.nameFa.trim() + : serialized.business.name, + } + : undefined, user: serialized.user ? { firstName: serialized.user.firstName, lastName: serialized.user.lastName } : null,