mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 21:00:31 +00:00
add server to monorepo.
This commit is contained in:
34
packages/server/src/services/Items/GetItem.ts
Normal file
34
packages/server/src/services/Items/GetItem.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
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());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user