add server to monorepo.

This commit is contained in:
a.bouhuolia
2023-02-03 11:57:50 +02:00
parent 28e309981b
commit 80b97b5fdc
1303 changed files with 137049 additions and 0 deletions

View File

@@ -0,0 +1,65 @@
import { Service, Inject } from 'typedi';
import HasTenancyService from '@/services/Tenancy/TenancyService';
import events from '@/subscribers/events';
import {
IApplyCreditToInvoicesCreatedPayload,
IApplyCreditToInvoicesDeletedPayload,
} from '@/interfaces';
import CreditNoteApplySyncInvoicesCreditedAmount from './CreditNoteApplySyncInvoices';
@Service()
export default class CreditNoteApplySyncInvoicesCreditedAmountSubscriber {
@Inject()
tenancy: HasTenancyService;
@Inject()
syncInvoicesWithCreditNote: CreditNoteApplySyncInvoicesCreditedAmount;
/**
* Attaches events with handlers.
*/
attach(bus) {
bus.subscribe(
events.creditNote.onApplyToInvoicesCreated,
this.incrementAppliedInvoicesOnceCreditCreated
);
bus.subscribe(
events.creditNote.onApplyToInvoicesDeleted,
this.decrementAppliedInvoicesOnceCreditDeleted
);
}
/**
* Increment invoices credited amount once the credit note apply to invoices transaction
* @param {IApplyCreditToInvoicesCreatedPayload} payload -
*/
private incrementAppliedInvoicesOnceCreditCreated = async ({
trx,
tenantId,
creditNoteAppliedInvoices,
}: IApplyCreditToInvoicesCreatedPayload) => {
await this.syncInvoicesWithCreditNote.incrementInvoicesCreditedAmount(
tenantId,
creditNoteAppliedInvoices,
trx
);
};
/**
*
* @param {IApplyCreditToInvoicesDeletedPayload} payload -
*/
private decrementAppliedInvoicesOnceCreditDeleted = async ({
trx,
creditNoteAppliedToInvoice,
tenantId,
}: IApplyCreditToInvoicesDeletedPayload) => {
// Decrement invoice credited amount.
await this.syncInvoicesWithCreditNote.decrementInvoiceCreditedAmount(
tenantId,
creditNoteAppliedToInvoice.invoiceId,
creditNoteAppliedToInvoice.amount,
trx
);
};
}