mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-15 12:20:31 +00:00
31 lines
845 B
TypeScript
31 lines
845 B
TypeScript
import { Inject, Service } from 'typedi';
|
|
import { ServiceError } from '@/exceptions';
|
|
import TenancyService from '@/services/Tenancy/TenancyService';
|
|
import { ERRORS } from './constants';
|
|
|
|
@Service()
|
|
export default class DeleteCustomerLinkedCreidtNote {
|
|
@Inject()
|
|
tenancy: TenancyService;
|
|
|
|
/**
|
|
* Validate the given customer has no linked credit note transactions.
|
|
* @param {number} tenantId
|
|
* @param {number} creditNoteId
|
|
*/
|
|
public validateCustomerHasNoCreditTransaction = async (
|
|
tenantId: number,
|
|
customerId: number
|
|
) => {
|
|
const { CreditNote } = this.tenancy.models(tenantId);
|
|
|
|
const associatedCredits = await CreditNote.query().where(
|
|
'customerId',
|
|
customerId
|
|
);
|
|
if (associatedCredits.length > 0) {
|
|
throw new ServiceError(ERRORS.CUSTOMER_HAS_LINKED_CREDIT_NOTES);
|
|
}
|
|
};
|
|
}
|