refactor(nestjs): bank transactions matching

This commit is contained in:
Ahmed Bouhuolia
2025-06-05 14:41:26 +02:00
parent f87bd341e9
commit 51988dba3b
43 changed files with 484 additions and 105 deletions

View File

@@ -0,0 +1,24 @@
import { Controller, Get, Query } from '@nestjs/common';
import { GetItemsInventoryValuationListService } from './queries/GetItemsInventoryValuationList.service';
import { GetInventoyItemsCostQueryDto } from './dtos/GetInventoryItemsCostQuery.dto';
import { ApiOperation, ApiTags } from '@nestjs/swagger';
@Controller('inventory-cost')
@ApiTags('inventory-cost')
export class InventoryCostController {
constructor(
private readonly inventoryItemCost: GetItemsInventoryValuationListService,
) {}
@Get('items')
@ApiOperation({ summary: 'Get items inventory valuation list' })
async getItemsCost(
@Query() itemsCostsQueryDto: GetInventoyItemsCostQueryDto,
) {
const costs = await this.inventoryItemCost.getItemsInventoryValuationList(
itemsCostsQueryDto.itemsIds,
itemsCostsQueryDto.date,
);
return { costs };
}
}

View File

@@ -23,6 +23,8 @@ import { InventoryItemOpeningAvgCostService } from './commands/InventoryItemOpen
import { InventoryCostSubscriber } from './subscribers/InventoryCost.subscriber';
import { SaleInvoicesModule } from '../SaleInvoices/SaleInvoices.module';
import { ImportModule } from '../Import/Import.module';
import { GetItemsInventoryValuationListService } from './queries/GetItemsInventoryValuationList.service';
import { InventoryCostController } from './InventoryCost.controller';
const models = [
RegisterTenancyModel(InventoryCostLotTracker),
@@ -54,6 +56,7 @@ const models = [
InventoryItemCostService,
InventoryItemOpeningAvgCostService,
InventoryCostSubscriber,
GetItemsInventoryValuationListService
],
exports: [
...models,
@@ -61,5 +64,6 @@ const models = [
InventoryItemCostService,
InventoryComputeCostService,
],
controllers: [InventoryCostController]
})
export class InventoryCostModule {}

View File

@@ -0,0 +1,26 @@
import {
ArrayMinSize,
IsArray,
IsDateString,
IsNotEmpty,
} from 'class-validator';
import { ApiProperty } from '@nestjs/swagger';
export class GetInventoyItemsCostQueryDto {
@IsDateString()
@IsNotEmpty()
@ApiProperty({
description: 'The date to get the inventory cost for',
example: '2021-01-01',
})
date: Date;
@IsArray()
@IsNotEmpty()
@ArrayMinSize(1)
@ApiProperty({
description: 'The ids of the items to get the inventory cost for',
example: [1, 2, 3],
})
itemsIds: Array<number>;
}

View File

@@ -0,0 +1,25 @@
import { Injectable } from '@nestjs/common';
import { InventoryItemCostService } from '../commands/InventoryCosts.service';
import { IInventoryItemCostMeta } from '../types/InventoryCost.types';
@Injectable()
export class GetItemsInventoryValuationListService {
constructor(private readonly inventoryCost: InventoryItemCostService) {}
/**
* Retrieves the items inventory valuation list.
* @param {number[]} itemsId
* @param {Date} date
* @returns {Promise<IInventoryItemCostMeta[]>}
*/
public getItemsInventoryValuationList = async (
itemsId: number[],
date: Date,
): Promise<IInventoryItemCostMeta[]> => {
const itemsMap = await this.inventoryCost.getItemsInventoryValuation(
itemsId,
date,
);
return [...itemsMap.values()];
};
}