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

38 lines
1.1 KiB
TypeScript
Raw Normal View History

2026-03-09 20:23:48 +00:00
import { CompositeSpecification, type UniqueID } from "@repo/rdx-ddd";
import type { Transaction } from "sequelize";
import type { ICustomerRepository } from "../../application";
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(
2026-03-09 20:23:48 +00:00
private readonly repository: ICustomerRepository,
2025-09-14 10:50:29 +00:00
private readonly companyId: UniqueID,
2025-10-28 17:52:30 +00:00
private readonly transaction?: Transaction
2025-09-14 10:50:29 +00:00
) {
super();
}
public async isSatisfiedBy(customerId: UniqueID): Promise<boolean> {
2026-03-09 20:23:48 +00:00
const existsCheck = await this.repository.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
}
}