mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 12:50:38 +00:00
35 lines
1.0 KiB
TypeScript
35 lines
1.0 KiB
TypeScript
import { Inject } from 'typedi';
|
|
import { IItem } from '@/interfaces';
|
|
import HasTenancyService from '@/services/Tenancy/TenancyService';
|
|
import { TransformerInjectable } from '@/lib/Transformer/TransformerInjectable';
|
|
import ItemTransformer from './ItemTransformer';
|
|
|
|
@Inject()
|
|
export class GetItem {
|
|
@Inject()
|
|
private tenancy: HasTenancyService;
|
|
|
|
@Inject()
|
|
private transformer: TransformerInjectable;
|
|
|
|
/**
|
|
* Retrieve the item details of the given id with associated details.
|
|
* @param {number} tenantId
|
|
* @param {number} itemId
|
|
*/
|
|
public async getItem(tenantId: number, itemId: number): Promise<IItem> {
|
|
const { Item } = this.tenancy.models(tenantId);
|
|
|
|
const item = await Item.query()
|
|
.findById(itemId)
|
|
.withGraphFetched('sellAccount')
|
|
.withGraphFetched('inventoryAccount')
|
|
.withGraphFetched('category')
|
|
.withGraphFetched('costAccount')
|
|
.withGraphFetched('itemWarehouses.warehouse')
|
|
.throwIfNotFound();
|
|
|
|
return this.transformer.transform(tenantId, item, new ItemTransformer());
|
|
}
|
|
}
|