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 { constructor( private readonly repository: ICustomerRepository, private readonly companyId: UniqueID, private readonly transaction?: Transaction ) { super(); } public async isSatisfiedBy(customerId: UniqueID): Promise { 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; } }