|
1
|
import { Context } from "@medusajs/framework/types" |
|
2
|
import { BigNumber, ModulesSdkUtils } from "@medusajs/framework/utils" |
|
3
|
import { applyEntityHooks } from "../utils/apply-decorators" |
|
4
|
|
|
5
|
import { InventoryLevel } from "@models" |
|
6
|
import { InventoryLevelRepository } from "@repositories" |
|
7
|
|
|
8
|
type InjectedDependencies = { |
|
9
|
inventoryLevelRepository: InventoryLevelRepository |
|
10
|
} |
|
11
|
|
|
12
|
export default class InventoryLevelService extends ModulesSdkUtils.MedusaInternalService< |
|
13
|
InjectedDependencies, |
|
14
|
typeof InventoryLevel |
|
15
|
>(InventoryLevel) { |
|
16
|
protected readonly inventoryLevelRepository: InventoryLevelRepository |
|
17
|
|
|
18
|
constructor(container: InjectedDependencies) { |
|
19
|
super(container) |
|
20
|
this.inventoryLevelRepository = container.inventoryLevelRepository |
|
21
|
} |
|
22
|
|
|
23
|
async retrieveStockedQuantity( |
|
24
|
inventoryItemId: string, |
|
25
|
locationIds: string[] | string, |
|
26
|
context: Context = {} |
|
27
|
): Promise<BigNumber> { |
|
28
|
const locationIdArray = Array.isArray(locationIds) |
|
29
|
? locationIds |
|
30
|
: [locationIds] |
|
31
|
|
|
32
|
return await this.inventoryLevelRepository.getStockedQuantity( |
|
33
|
inventoryItemId, |
|
34
|
locationIdArray, |
|
35
|
context |
|
36
|
) |
|
37
|
} |
|
38
|
|
|
39
|
async getAvailableQuantity( |
|
40
|
inventoryItemId: string, |
|
41
|
locationIds: string[] | string, |
|
42
|
context: Context = {} |
|
43
|
): Promise<BigNumber> { |
|
44
|
const locationIdArray = Array.isArray(locationIds) |
|
45
|
? locationIds |
|
46
|
: [locationIds] |
|
47
|
|
|
48
|
return await this.inventoryLevelRepository.getAvailableQuantity( |
|
49
|
inventoryItemId, |
|
50
|
locationIdArray, |
|
51
|
context |
|
52
|
) |
|
53
|
} |
|
54
|
|
|
55
|
async getReservedQuantity( |
|
56
|
inventoryItemId: string, |
|
57
|
locationIds: string[] | string, |
|
58
|
context: Context = {} |
|
59
|
) { |
|
60
|
if (!Array.isArray(locationIds)) { |
|
61
|
locationIds = [locationIds] |
|
62
|
} |
|
63
|
|
|
64
|
return await this.inventoryLevelRepository.getReservedQuantity( |
|
65
|
inventoryItemId, |
|
66
|
locationIds, |
|
67
|
context |
|
68
|
) |
|
69
|
} |
|
70
|
} |
|
71
|
|
|
72
|
applyEntityHooks() |