Uecko_ERP/modules/customers/src/api/application/specs/customer-not-exists.spec.ts
2026-03-09 21:23:48 +01:00

38 lines
1.1 KiB
TypeScript

import { CompositeSpecification, type UniqueID } from "@repo/rdx-ddd";
import type { Transaction } from "sequelize";
import type { ICustomerRepository } from "../../application";
import { logger } from "../../helpers";
export class CustomerNotExistsInCompanySpecification extends CompositeSpecification<UniqueID> {
constructor(
private readonly repository: ICustomerRepository,
private readonly companyId: UniqueID,
private readonly transaction?: Transaction
) {
super();
}
public async isSatisfiedBy(customerId: UniqueID): Promise<boolean> {
const existsCheck = await this.repository.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;
}
}