refactor: wip to nestjs

This commit is contained in:
Ahmed Bouhuolia
2024-12-25 00:43:55 +02:00
parent 336171081e
commit a6932d76f3
249 changed files with 21314 additions and 1616 deletions

View File

@@ -0,0 +1,37 @@
import { Inject, Injectable } from '@nestjs/common';
import { PaymentReceivedValidators } from '../commands/PaymentReceivedValidators.service';
import { SaleInvoice } from '../../SaleInvoices/models/SaleInvoice';
import { PaymentReceived } from '../models/PaymentReceived';
@Injectable()
export class GetPaymentReceivedInvoices {
constructor(
@Inject(PaymentReceived.name)
private paymentReceiveModel: typeof PaymentReceived,
private validators: PaymentReceivedValidators,
) {}
/**
* Retrieve sale invoices that associated to the given payment receive.
* @param {number} paymentReceiveId - Payment receive id.
* @return {Promise<ISaleInvoice>}
*/
public async getPaymentReceiveInvoices(paymentReceiveId: number) {
const paymentReceive = await this.paymentReceiveModel
.query()
.findById(paymentReceiveId)
.withGraphFetched('entries');
// Validates the payment receive existence.
this.validators.validatePaymentExistance(paymentReceive);
const paymentReceiveInvoicesIds = paymentReceive.entries.map(
(entry) => entry.invoiceId,
);
const saleInvoices = await SaleInvoice.query().whereIn(
'id',
paymentReceiveInvoicesIds,
);
return saleInvoices;
}
}