mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-20 23:00:34 +00:00
feat(nestjs): migrate to NestJS
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
import { GetItemWarehouseTransformer } from './GettItemWarehouseTransformer';
|
||||
import { Inject, Injectable } from '@nestjs/common';
|
||||
import { ItemWarehouseQuantity } from '../models/ItemWarehouseQuantity';
|
||||
import { Item } from '@/modules/Items/models/Item';
|
||||
import { TransformerInjectable } from '@/modules/Transformer/TransformerInjectable.service';
|
||||
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
|
||||
|
||||
@Injectable()
|
||||
export class GetItemWarehouses {
|
||||
constructor(
|
||||
@Inject(ItemWarehouseQuantity.name)
|
||||
private readonly itemWarehouseQuantityModel: TenantModelProxy<
|
||||
typeof ItemWarehouseQuantity
|
||||
>,
|
||||
|
||||
@Inject(Item.name)
|
||||
private readonly itemModel: TenantModelProxy<typeof Item>,
|
||||
private readonly transformer: TransformerInjectable,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Retrieves the item warehouses.
|
||||
* @param {number} itemId
|
||||
* @returns
|
||||
*/
|
||||
public getItemWarehouses = async (itemId: number) => {
|
||||
// Retrieves specific item or throw not found service error.
|
||||
const item = await this.itemModel()
|
||||
.query()
|
||||
.findById(itemId)
|
||||
.throwIfNotFound();
|
||||
|
||||
const itemWarehouses = await this.itemWarehouseQuantityModel()
|
||||
.query()
|
||||
.where('itemId', itemId)
|
||||
.withGraphFetched('warehouse');
|
||||
|
||||
// Retrieves the transformed items warehouses.
|
||||
return this.transformer.transform(
|
||||
itemWarehouses,
|
||||
new GetItemWarehouseTransformer(),
|
||||
);
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
import { Transformer } from '@/modules/Transformer/Transformer';
|
||||
import { Item } from '@/modules/Items/models/Item';
|
||||
|
||||
export class GetItemWarehouseTransformer extends Transformer {
|
||||
/**
|
||||
* Include these attributes to sale invoice object.
|
||||
* @returns {Array}
|
||||
*/
|
||||
public includeAttributes = (): string[] => {
|
||||
return [
|
||||
'warehouseId',
|
||||
'warehouseName',
|
||||
'warehouseCode',
|
||||
'quantityOnHandFormatted',
|
||||
];
|
||||
};
|
||||
|
||||
/**
|
||||
* Exclude the warehouse attribute.
|
||||
* @returns {Array}
|
||||
*/
|
||||
public excludeAttributes = (): string[] => {
|
||||
return ['warehouse'];
|
||||
};
|
||||
|
||||
/**
|
||||
* Formatted sell price.
|
||||
* @param item
|
||||
* @returns {string}
|
||||
*/
|
||||
public quantityOnHandFormatted(item: Item): string {
|
||||
return this.formatNumber(item.quantityOnHand, { money: false });
|
||||
}
|
||||
|
||||
public warehouseCode(item: Item): string {
|
||||
return item.warehouse.code;
|
||||
}
|
||||
|
||||
public warehouseName(item: Item): string {
|
||||
return item.warehouse.name;
|
||||
}
|
||||
|
||||
public warehouseId(item: Item): number {
|
||||
return item.warehouse.id;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user