2025-05-04 20:06:57 +00:00
|
|
|
import { SequelizeRepository } from "@/core";
|
2025-03-18 08:05:00 +00:00
|
|
|
import { Transaction } from "sequelize";
|
|
|
|
|
|
2025-05-04 20:06:57 +00:00
|
|
|
export class ContactRepository extends SequelizeRepository<Contact> implements IContactRepository {
|
2025-03-18 08:05:00 +00:00
|
|
|
protected mapper: IContactMapper;
|
|
|
|
|
|
|
|
|
|
public constructor(props: {
|
|
|
|
|
mapper: IContactMapper;
|
|
|
|
|
adapter: ISequelizeAdapter;
|
|
|
|
|
transaction: Transaction;
|
|
|
|
|
}) {
|
|
|
|
|
const { adapter, mapper, transaction } = props;
|
|
|
|
|
super({ adapter, transaction });
|
|
|
|
|
this.mapper = mapper;
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-04 20:06:57 +00:00
|
|
|
public async getById2(id: UniqueID, billingAddressId: UniqueID, shippingAddressId: UniqueID) {
|
2025-03-18 08:05:00 +00:00
|
|
|
const Contact_Model = this.adapter.getModel("Contact_Model");
|
|
|
|
|
const ContactAddress_Model = this.adapter.getModel("ContactAddress_Model");
|
|
|
|
|
|
|
|
|
|
const rawContact: any = await Contact_Model.findOne({
|
|
|
|
|
where: { id: id.toString() },
|
|
|
|
|
include: [
|
|
|
|
|
{
|
|
|
|
|
model: ContactAddress_Model,
|
|
|
|
|
as: "billingAddress",
|
|
|
|
|
where: {
|
|
|
|
|
id: billingAddressId.toString(),
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
model: ContactAddress_Model,
|
|
|
|
|
as: "shippingAddress",
|
|
|
|
|
where: {
|
|
|
|
|
id: shippingAddressId.toString(),
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
transaction: this.transaction,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (!rawContact === true) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return this.mapper.mapToDomain(rawContact);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async getById(id: UniqueID): Promise<Contact | null> {
|
|
|
|
|
const rawContact: any = await this._getById("Contact_Model", id, {
|
|
|
|
|
include: [{ all: true }],
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (!rawContact === true) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return this.mapper.mapToDomain(rawContact);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async exists(id: UniqueID): Promise<boolean> {
|
|
|
|
|
return this._exists("Customer", "id", id.toString());
|
|
|
|
|
}
|
|
|
|
|
}
|