Uecko_ERP/modules/customers/src/common/features/get-customer/utils/build-customer-data.ts
2026-07-03 09:37:12 +02:00

72 lines
2.0 KiB
TypeScript

import type { Customer } from "../../../../web/shared";
import type { CustomerData } from "../entities";
/**
* Mapper explícito para desacoplar UI del shape de customers/shared.
*/
export const buildCustomerData = (customer: Customer): CustomerData => {
return {
id: customer.id,
status: customer.status,
reference: customer.reference,
isCompany: customer.isCompany,
name: customer.name,
tradeName: customer.tradeName,
tin: customer.tin,
address: {
street: customer.address.street,
street2: null,
city: customer.address.city,
province: customer.address.province,
postalCode: customer.address.postalCode,
country: customer.address.country,
},
contact: {
emailPrimary: customer.contact.primaryEmail,
emailSecondary: customer.contact.secondaryEmail,
phonePrimary: customer.contact.primaryPhone,
phoneSecondary: customer.contact.secondaryPhone,
mobilePrimary: customer.contact.primaryMobile,
mobileSecondary: customer.contact.secondaryMobile,
fax: customer.contact.fax,
website: customer.contact.website,
},
legalRecord: customer.legalRecord,
paymentMethod: customer.paymentMethod
? {
id: customer.paymentMethod.id,
name: customer.paymentMethod.name,
description: customer.paymentMethod.description,
}
: null,
paymentTerm: customer.paymentTerm
? {
id: customer.paymentTerm.id,
description: customer.paymentTerm.description,
}
: null,
taxRegime: customer.taxRegime
? {
code: customer.taxRegime.code,
description: customer.taxRegime.description,
}
: null,
fiscalDefaults: {
usesEquivalenceSurcharge: customer.fiscalDefaults.usesEquivalenceSurcharge,
usesRetention: customer.fiscalDefaults.usesRetention,
},
languageCode: customer.languageCode,
currencyCode: customer.currencyCode,
};
};