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

36 lines
999 B
TypeScript
Raw Normal View History

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
}
}