mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-15 20:30:33 +00:00
refactor(nestjs): bank transactions matching
This commit is contained in:
@@ -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 };
|
||||
}
|
||||
}
|
||||
@@ -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 {}
|
||||
|
||||
@@ -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>;
|
||||
}
|
||||
@@ -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()];
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user