mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 21:30:31 +00:00
refactor: split the services to multiple service classes (#202)
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
import { Service, Inject } from 'typedi';
|
||||
import HasTenancyService from '@/services/Tenancy/TenancyService';
|
||||
import { InvoicePaymentTransactionTransformer } from './InvoicePaymentTransactionTransformer';
|
||||
import { TransformerInjectable } from '@/lib/Transformer/TransformerInjectable';
|
||||
|
||||
@Service()
|
||||
export class GetInvoicePaymentsService {
|
||||
@Inject()
|
||||
private tenancy: HasTenancyService;
|
||||
|
||||
@Inject()
|
||||
private transformer: TransformerInjectable;
|
||||
|
||||
/**
|
||||
* Retrieve the invoice assocaited payments transactions.
|
||||
* @param {number} tenantId - Tenant id.
|
||||
* @param {number} invoiceId - Invoice id.
|
||||
*/
|
||||
public getInvoicePayments = async (tenantId: number, invoiceId: number) => {
|
||||
const { PaymentReceiveEntry } = this.tenancy.models(tenantId);
|
||||
|
||||
const paymentsEntries = await PaymentReceiveEntry.query()
|
||||
.where('invoiceId', invoiceId)
|
||||
.withGraphJoined('payment.depositAccount')
|
||||
.withGraphJoined('invoice')
|
||||
.orderBy('payment:paymentDate', 'ASC');
|
||||
|
||||
return this.transformer.transform(
|
||||
tenantId,
|
||||
paymentsEntries,
|
||||
new InvoicePaymentTransactionTransformer()
|
||||
);
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user