refactor(nestjs): landed cost

This commit is contained in:
Ahmed Bouhuolia
2025-06-11 14:04:37 +02:00
parent 1130975efd
commit ff93168d72
28 changed files with 622 additions and 417 deletions

View File

@@ -8,6 +8,7 @@ import { OpenBillService } from './commands/OpenBill.service';
import { Injectable } from '@nestjs/common';
import { GetBillsService } from './queries/GetBills.service';
import { CreateBillDto, EditBillDto } from './dtos/Bill.dto';
import { GetBillPaymentTransactionsService } from './queries/GetBillPayments';
// import { GetBillPayments } from './queries/GetBillPayments';
// import { GetBills } from './queries/GetBills';
@@ -21,7 +22,7 @@ export class BillsApplication {
private getDueBillsService: GetDueBills,
private openBillService: OpenBillService,
private getBillsService: GetBillsService,
// private getBillPaymentsService: GetBillPayments,
private getBillPaymentTransactionsService: GetBillPaymentTransactionsService,
) {}
/**
@@ -71,7 +72,6 @@ export class BillsApplication {
/**
* Open the given bill.
* @param {number} tenantId
* @param {number} billId
* @returns {Promise<void>}
*/
@@ -91,10 +91,11 @@ export class BillsApplication {
/**
* Retrieve the specific bill associated payment transactions.
* @param {number} tenantId
* @param {number} billId
*/
// public getBillPayments(billId: number) {
// return this.getBillPaymentsService.getBillPayments(billId);
// }
public getBillPaymentTransactions(billId: number) {
return this.getBillPaymentTransactionsService.getBillPaymentTransactions(
billId,
);
}
}

View File

@@ -60,6 +60,18 @@ export class BillsController {
return this.billsApplication.getBills(filterDTO);
}
@Get(':id/payment-transactions')
@ApiOperation({ summary: 'Retrieve the specific bill associated payment transactions.' })
@ApiParam({
name: 'id',
required: true,
type: Number,
description: 'The bill id',
})
getBillPaymentTransactions(@Param('id') billId: number) {
return this.billsApplication.getBillPaymentTransactions(billId);
}
@Get(':id')
@ApiOperation({ summary: 'Retrieves the bill details.' })
@ApiParam({

View File

@@ -28,6 +28,7 @@ import { DynamicListModule } from '../DynamicListing/DynamicList.module';
import { InventoryCostModule } from '../InventoryCost/InventoryCost.module';
import { BillsExportable } from './commands/BillsExportable';
import { BillsImportable } from './commands/BillsImportable';
import { GetBillPaymentTransactionsService } from './queries/GetBillPayments';
@Module({
imports: [
@@ -60,7 +61,8 @@ import { BillsImportable } from './commands/BillsImportable';
BillInventoryTransactions,
BillWriteInventoryTransactionsSubscriber,
BillsExportable,
BillsImportable
BillsImportable,
GetBillPaymentTransactionsService,
],
controllers: [BillsController],
exports: [BillsExportable, BillsImportable],

View File

@@ -2,12 +2,13 @@ import { Inject, Injectable } from '@nestjs/common';
import { BillPaymentEntry } from '@/modules/BillPayments/models/BillPaymentEntry';
import { BillPaymentTransactionTransformer } from '@/modules/BillPayments/queries/BillPaymentTransactionTransformer';
import { TransformerInjectable } from '@/modules/Transformer/TransformerInjectable.service';
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
@Injectable()
export class GetBillPayments {
export class GetBillPaymentTransactionsService {
constructor(
@Inject(BillPaymentEntry.name)
private billPaymentEntryModel: typeof BillPaymentEntry,
private billPaymentEntryModel: TenantModelProxy<typeof BillPaymentEntry>,
private transformer: TransformerInjectable,
) {}
@@ -15,8 +16,8 @@ export class GetBillPayments {
* Retrieve the specific bill associated payment transactions.
* @param {number} billId - Bill id.
*/
public getBillPayments = async (billId: number) => {
const billsEntries = await this.billPaymentEntryModel
public getBillPaymentTransactions = async (billId: number) => {
const billsEntries = await this.billPaymentEntryModel()
.query()
.where('billId', billId)
.withGraphJoined('payment.paymentAccount')