mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 21:00:31 +00:00
add server to monorepo.
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
import { Inject, Service } from 'typedi';
|
||||
import { ISaleInvoice } from '@/interfaces';
|
||||
import BaseCreditNotes from './CreditNotes';
|
||||
import { CreditNoteAppliedInvoiceTransformer } from './CreditNoteAppliedInvoiceTransformer';
|
||||
import { TransformerInjectable } from '@/lib/Transformer/TransformerInjectable';
|
||||
|
||||
@Service()
|
||||
export default class GetCreditNoteAssociatedAppliedInvoices extends BaseCreditNotes {
|
||||
@Inject()
|
||||
private transformer: TransformerInjectable;
|
||||
|
||||
/**
|
||||
* Retrieve credit note associated invoices to apply.
|
||||
* @param {number} tenantId
|
||||
* @param {number} creditNoteId
|
||||
* @returns {Promise<ISaleInvoice[]>}
|
||||
*/
|
||||
public getCreditAssociatedAppliedInvoices = async (
|
||||
tenantId: number,
|
||||
creditNoteId: number
|
||||
): Promise<ISaleInvoice[]> => {
|
||||
const { CreditNoteAppliedInvoice } = this.tenancy.models(tenantId);
|
||||
|
||||
// Retireve credit note or throw not found service error.
|
||||
const creditNote = await this.getCreditNoteOrThrowError(
|
||||
tenantId,
|
||||
creditNoteId
|
||||
);
|
||||
const appliedToInvoices = await CreditNoteAppliedInvoice.query()
|
||||
.where('credit_note_id', creditNoteId)
|
||||
.withGraphFetched('saleInvoice')
|
||||
.withGraphFetched('creditNote');
|
||||
|
||||
// Transformes credit note applied to invoices.
|
||||
return this.transformer.transform(
|
||||
tenantId,
|
||||
appliedToInvoices,
|
||||
new CreditNoteAppliedInvoiceTransformer()
|
||||
);
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user