2025-09-14 10:50:29 +00:00
|
|
|
import { CompositeSpecification, UniqueID } from "@repo/rdx-ddd";
|
|
|
|
|
import { CustomerService } from "../../domain";
|
2025-09-23 10:40:49 +00:00
|
|
|
import { logger } from "../../helpers";
|
2025-09-14 10:50:29 +00:00
|
|
|
|
|
|
|
|
export class CustomerNotExistsInCompanySpecification extends CompositeSpecification<UniqueID> {
|
|
|
|
|
constructor(
|
|
|
|
|
private readonly service: CustomerService,
|
|
|
|
|
private readonly companyId: UniqueID,
|
|
|
|
|
private readonly transaction?: any
|
|
|
|
|
) {
|
|
|
|
|
super();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async isSatisfiedBy(customerId: UniqueID): Promise<boolean> {
|
2025-09-23 10:40:49 +00:00
|
|
|
const existsCheck = await this.service.existsByIdInCompany(
|
2025-09-14 10:50:29 +00:00
|
|
|
this.companyId,
|
2025-09-23 10:40:49 +00:00
|
|
|
customerId,
|
2025-09-14 10:50:29 +00:00
|
|
|
this.transaction
|
|
|
|
|
);
|
2025-09-23 10:40:49 +00:00
|
|
|
|
|
|
|
|
if (existsCheck.isFailure) {
|
|
|
|
|
throw existsCheck.error;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const customerExists = existsCheck.data;
|
|
|
|
|
logger.debug(
|
|
|
|
|
`customerExists => ${customerExists}, ${JSON.stringify({ customerId, companyId: this.companyId }, null, 2)}`,
|
|
|
|
|
{
|
|
|
|
|
label: "CustomerNotExistsInCompanySpecification",
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return customerExists === false;
|
2025-09-14 10:50:29 +00:00
|
|
|
}
|
|
|
|
|
}
|