Uecko_ERP/modules/customer-invoices/src/api/infrastructure/mappers/customer-invoiceParticipantAddress.mapper.ts.bak

88 lines
2.8 KiB
TypeScript
Raw Normal View History

2025-04-01 14:26:15 +00:00
import { ISequelizeMapper, SequelizeMapper } from "@/contexts/common/infrastructure";
2025-03-18 08:05:00 +00:00
import {
City,
Country,
Email,
Note,
Phone,
PostalCode,
Province,
Street,
UniqueID,
} from "@shared/contexts";
import {
2025-06-11 15:13:44 +00:00
ICustomerInvoiceParticipantAddressProps,
CustomerInvoiceCustomer,
CustomerInvoiceParticipantAddress,
2025-03-18 08:05:00 +00:00
} from "../../domain";
import { IInvoicingContext } from "../InvoicingContext";
import {
2025-06-11 15:13:44 +00:00
CustomerInvoiceParticipantAddress_Model,
TCreationCustomerInvoiceParticipantAddress_Model,
2025-03-18 08:05:00 +00:00
} from "../sequelize";
2025-06-11 15:13:44 +00:00
export interface ICustomerInvoiceParticipantAddressMapper
2025-03-18 08:05:00 +00:00
extends ISequelizeMapper<
2025-06-11 15:13:44 +00:00
CustomerInvoiceParticipantAddress_Model,
TCreationCustomerInvoiceParticipantAddress_Model,
CustomerInvoiceParticipantAddress
2025-03-18 08:05:00 +00:00
> {}
2025-06-11 15:13:44 +00:00
export const createCustomerInvoiceParticipantAddressMapper = (
2025-03-18 08:05:00 +00:00
context: IInvoicingContext
2025-06-11 15:13:44 +00:00
): ICustomerInvoiceParticipantAddressMapper => new CustomerInvoiceParticipantAddressMapper({ context });
2025-03-18 08:05:00 +00:00
2025-06-11 15:13:44 +00:00
class CustomerInvoiceParticipantAddressMapper
2025-03-18 08:05:00 +00:00
extends SequelizeMapper<
2025-06-11 15:13:44 +00:00
CustomerInvoiceParticipantAddress_Model,
TCreationCustomerInvoiceParticipantAddress_Model,
CustomerInvoiceParticipantAddress
2025-03-18 08:05:00 +00:00
>
2025-06-11 15:13:44 +00:00
implements ICustomerInvoiceParticipantAddressMapper
2025-03-18 08:05:00 +00:00
{
2025-06-11 15:13:44 +00:00
protected toDomainMappingImpl(source: CustomerInvoiceParticipantAddress_Model, params: any) {
2025-03-18 08:05:00 +00:00
const id = this.mapsValue(source, "address_id", UniqueID.create);
2025-06-11 15:13:44 +00:00
const props: ICustomerInvoiceParticipantAddressProps = {
2025-03-18 08:05:00 +00:00
type: source.type,
street: this.mapsValue(source, "street", Street.create),
city: this.mapsValue(source, "city", City.create),
province: this.mapsValue(source, "province", Province.create),
postalCode: this.mapsValue(source, "postal_code", PostalCode.create),
country: this.mapsValue(source, "country", Country.create),
email: this.mapsValue(source, "email", Email.create),
phone: this.mapsValue(source, "phone", Phone.create),
notes: this.mapsValue(source, "notes", Note.create),
};
2025-06-11 15:13:44 +00:00
const addressOrError = CustomerInvoiceParticipantAddress.create(props, id);
2025-03-18 08:05:00 +00:00
if (addressOrError.isFailure) {
throw addressOrError.error;
}
return addressOrError.object;
}
protected toPersistenceMappingImpl(
2025-06-11 15:13:44 +00:00
source: CustomerInvoiceParticipantAddress,
params: { sourceParent: CustomerInvoiceCustomer }
2025-03-18 08:05:00 +00:00
) {
const { sourceParent } = params;
return {
address_id: source.id.toPrimitive(),
participant_id: sourceParent.id.toPrimitive(),
type: String(source.type),
title: source.title,
street: source.street.toPrimitive(),
city: source.city.toPrimitive(),
postal_code: source.postalCode.toPrimitive(),
province: source.province.toPrimitive(),
country: source.country.toPrimitive(),
email: source.email.toPrimitive(),
phone: source.phone.toPrimitive(),
};
}
}