mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-24 16:49:48 +00:00
- Add missing DELETE /credit-notes/applied-invoices/:id endpoint - Fix CreditNotesApplyInvoice controller to use correct service methods - Add missing GetCreditNoteAssociatedInvoicesToApply endpoint - Add proper DTO for ApplyCreditNoteToInvoices - Update frontend creditNote hook to use correct API paths Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
48 lines
1.5 KiB
TypeScript
48 lines
1.5 KiB
TypeScript
import { OnEvent } from '@nestjs/event-emitter';
|
|
import { Injectable } from '@nestjs/common';
|
|
import {
|
|
IApplyCreditToInvoicesCreatedPayload,
|
|
IApplyCreditToInvoicesDeletedPayload,
|
|
} from '../types/CreditNoteApplyInvoice.types';
|
|
import { CreditNoteApplySyncInvoicesCreditedAmount } from '../commands/CreditNoteApplySyncInvoices.service';
|
|
import { events } from '@/common/events/events';
|
|
|
|
@Injectable()
|
|
export class CreditNoteApplySyncInvoicesCreditedAmountSubscriber {
|
|
constructor(
|
|
private readonly syncInvoicesWithCreditNote: CreditNoteApplySyncInvoicesCreditedAmount,
|
|
) {}
|
|
|
|
/**
|
|
* Increment invoices credited amount once the credit note apply to invoices transaction
|
|
* @param {IApplyCreditToInvoicesCreatedPayload} payload -
|
|
*/
|
|
@OnEvent(events.creditNote.onApplyToInvoicesCreated)
|
|
async incrementAppliedInvoicesOnceCreditCreated({
|
|
trx,
|
|
creditNoteAppliedInvoices,
|
|
}: IApplyCreditToInvoicesCreatedPayload) {
|
|
await this.syncInvoicesWithCreditNote.incrementInvoicesCreditedAmount(
|
|
creditNoteAppliedInvoices,
|
|
trx,
|
|
);
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @param {IApplyCreditToInvoicesDeletedPayload} payload -
|
|
*/
|
|
@OnEvent(events.creditNote.onApplyToInvoicesDeleted)
|
|
async decrementAppliedInvoicesOnceCreditDeleted({
|
|
trx,
|
|
creditNoteAppliedToInvoice,
|
|
}: IApplyCreditToInvoicesDeletedPayload) {
|
|
// Decrement invoice credited amount.
|
|
await this.syncInvoicesWithCreditNote.decrementInvoiceCreditedAmount(
|
|
creditNoteAppliedToInvoice.invoiceId,
|
|
creditNoteAppliedToInvoice.amount,
|
|
trx,
|
|
);
|
|
}
|
|
}
|