Uecko_ERP/modules/customers/src/api/application/specs/customer-not-exists.spec.ts

36 lines
999 B
TypeScript

import { CompositeSpecification, UniqueID } from "@repo/rdx-ddd";
import { CustomerService } from "../../domain";
import { logger } from "../../helpers";
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> {
const existsCheck = await this.service.existsByIdInCompany(
this.companyId,
customerId,
this.transaction
);
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;
}
}