88 lines
2.8 KiB
TypeScript
88 lines
2.8 KiB
TypeScript
import { ISequelizeMapper, SequelizeMapper } from "@/contexts/common/infrastructure";
|
|
import {
|
|
City,
|
|
Country,
|
|
Email,
|
|
Note,
|
|
Phone,
|
|
PostalCode,
|
|
Province,
|
|
Street,
|
|
UniqueID,
|
|
} from "@shared/contexts";
|
|
import {
|
|
ICustomerInvoiceParticipantAddressProps,
|
|
CustomerInvoiceCustomer,
|
|
CustomerInvoiceParticipantAddress,
|
|
} from "../../domain";
|
|
import { IInvoicingContext } from "../InvoicingContext";
|
|
import {
|
|
CustomerInvoiceParticipantAddress_Model,
|
|
TCreationCustomerInvoiceParticipantAddress_Model,
|
|
} from "../sequelize";
|
|
|
|
export interface ICustomerInvoiceParticipantAddressMapper
|
|
extends ISequelizeMapper<
|
|
CustomerInvoiceParticipantAddress_Model,
|
|
TCreationCustomerInvoiceParticipantAddress_Model,
|
|
CustomerInvoiceParticipantAddress
|
|
> {}
|
|
|
|
export const createCustomerInvoiceParticipantAddressMapper = (
|
|
context: IInvoicingContext
|
|
): ICustomerInvoiceParticipantAddressMapper => new CustomerInvoiceParticipantAddressMapper({ context });
|
|
|
|
class CustomerInvoiceParticipantAddressMapper
|
|
extends SequelizeMapper<
|
|
CustomerInvoiceParticipantAddress_Model,
|
|
TCreationCustomerInvoiceParticipantAddress_Model,
|
|
CustomerInvoiceParticipantAddress
|
|
>
|
|
implements ICustomerInvoiceParticipantAddressMapper
|
|
{
|
|
protected toDomainMappingImpl(source: CustomerInvoiceParticipantAddress_Model, params: any) {
|
|
const id = this.mapsValue(source, "address_id", UniqueID.create);
|
|
|
|
const props: ICustomerInvoiceParticipantAddressProps = {
|
|
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),
|
|
};
|
|
|
|
const addressOrError = CustomerInvoiceParticipantAddress.create(props, id);
|
|
|
|
if (addressOrError.isFailure) {
|
|
throw addressOrError.error;
|
|
}
|
|
|
|
return addressOrError.object;
|
|
}
|
|
|
|
protected toPersistenceMappingImpl(
|
|
source: CustomerInvoiceParticipantAddress,
|
|
params: { sourceParent: CustomerInvoiceCustomer }
|
|
) {
|
|
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(),
|
|
};
|
|
}
|
|
}
|