Skip to content

Commit 607ec52

Browse files
feat: added Update endpoint for MLI, interface updates
1 parent 01d05ef commit 607ec52

File tree

2 files changed

+89
-35
lines changed

2 files changed

+89
-35
lines changed

src/endpoints/multi-location-inventories.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,28 @@ class MultiLocationInventories {
3030
)
3131
}
3232

33-
Get(productId) {
34-
return this.request.send(`${this.endpoint}/${productId}`, 'GET')
33+
Get(inventoryId) {
34+
return this.request.send(`${this.endpoint}/${inventoryId}`, 'GET')
3535
}
3636

37-
Create(body) {
37+
Create(body, productId) {
3838
return this.request.send(`${this.endpoint}}`, 'POST', {
3939
type: 'stock',
40+
id: productId,
4041
attributes: body
4142
})
4243
}
4344

44-
Delete(productId) {
45-
return this.request.send(`${this.endpoint}/${productId}`, 'DELETE')
45+
Update(inventoryId, body) {
46+
return this.request.send(`${this.endpoint}/${inventoryId}`, 'PUT', {
47+
type: 'stock',
48+
id: inventoryId,
49+
attributes: body
50+
})
51+
}
52+
53+
Delete(inventoryId) {
54+
return this.request.send(`${this.endpoint}/${inventoryId}`, 'DELETE')
4655
}
4756

4857
Limit(value) {

src/types/multi-location-inventories.d.ts

Lines changed: 75 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,50 +4,81 @@
44
import { LocationsEndpoint } from './mli-locations'
55
import { Identifiable, Resource, ResourcePage } from './core'
66

7-
type StockType = 'stock'
7+
/**
8+
* Multi Location Inventory Types
9+
*/
10+
export type InventoryResourceType = 'stock'
811

9-
export interface StockMeta {
10-
timestamps: {
11-
created_at: string
12-
updated_at: string
13-
}
12+
/**
13+
* Base Types
14+
*/
15+
export interface Timestamps {
16+
created_at: string
17+
updated_at: string
18+
}
19+
20+
/**
21+
* Location-specific inventory quantities
22+
*/
23+
export interface LocationQuantities {
24+
available: number
25+
allocated: number
26+
total: number
27+
}
28+
29+
/**
30+
* Create Operation Types
31+
*/
32+
export interface LocationCreateQuantity {
33+
available: number
1434
}
1535

16-
export interface StockBaseLocations {
17-
[key: string]: {
18-
available: number
36+
export interface StockCreate {
37+
available?: number
38+
locations?: {
39+
[locationId: string]: LocationCreateQuantity
1940
}
2041
}
2142

22-
export interface StockBaseAttributes {
23-
product_id: string
24-
locations: StockBaseLocations
43+
/**
44+
* Update Operation Types
45+
*/
46+
export interface LocationUpdateQuantity {
47+
allocated?: number
48+
available?: number
2549
}
2650

27-
export interface StockResponseLocations {
28-
[key: string]: {
29-
available: number
30-
allocated: number
31-
total: number
51+
export interface StockUpdate {
52+
locations?: {
53+
[locationId: string]: LocationUpdateQuantity | null
3254
}
3355
}
34-
export interface StockResponseAttributes extends StockBaseAttributes {
56+
57+
/**
58+
* Response Types
59+
*/
60+
export interface StockLocationsMap {
61+
[locationId: string]: LocationQuantities
62+
}
63+
64+
export interface StockAttributes {
3565
allocated: number
66+
available: number
3667
total: number
37-
locations: StockResponseLocations
68+
locations: StockLocationsMap
3869
}
3970

40-
export interface StockResponse extends Identifiable, StockMeta {
41-
type: StockType
42-
attributes: StockResponseAttributes
71+
export interface StockResponse extends Identifiable {
72+
type: InventoryResourceType
73+
attributes: StockAttributes
74+
timestamps: Timestamps
4375
}
4476

4577
/**
46-
* Multi Location Inventories Endpoints
78+
* Multi Location Inventories Endpoint Interface
4779
*/
4880
export interface MultiLocationInventoriesEndpoint {
4981
endpoint: 'inventory'
50-
5182
Locations: LocationsEndpoint
5283

5384
/**
@@ -57,21 +88,35 @@ export interface MultiLocationInventoriesEndpoint {
5788

5889
/**
5990
* Get Stock for Product
60-
* @param productId The ID of the product.
91+
* @param inventoryId - The inventory identifier
6192
*/
62-
Get(productId: string): Promise<Resource<StockResponse>>
93+
Get(inventoryId: string): Promise<Resource<StockResponse>>
6394

6495
/**
6596
* Create Stock for Product
66-
* @param body - The base attributes of the inventory stock.
97+
* @param payload - Initial stock information with overall availability or per-location quantities
98+
* @param productId - Optional product identifier
99+
*/
100+
Create(
101+
payload: StockCreate,
102+
productId?: string
103+
): Promise<Resource<StockResponse>>
104+
105+
/**
106+
* Update Stock for Product
107+
* @param inventoryId - The inventory identifier
108+
* @param payload - Location-specific updates. Set location to null to remove it
67109
*/
68-
Create(body: StockBaseAttributes): Promise<Resource<StockResponse>>
110+
Update(
111+
inventoryId: string,
112+
payload: StockUpdate
113+
): Promise<Resource<StockResponse>>
69114

70115
/**
71116
* Delete Stock for Product
72-
* @param productId The ID of the product.
117+
* @param inventoryId - The inventory identifier
73118
*/
74-
Delete(productId: string): Promise<{}>
119+
Delete(inventoryId: string): Promise<{}>
75120

76121
Limit(value: number): MultiLocationInventoriesEndpoint
77122

0 commit comments

Comments
 (0)