Skip to content

Commit

Permalink
feat: added Update endpoint for MLI, interface updates (#35)
Browse files Browse the repository at this point in the history
BREAKING CHANGE:
  • Loading branch information
rostyk-kanafotskyy authored Oct 22, 2024
1 parent 01d05ef commit fe64e57
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 35 deletions.
19 changes: 14 additions & 5 deletions src/endpoints/multi-location-inventories.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,28 @@ class MultiLocationInventories {
)
}

Get(productId) {
return this.request.send(`${this.endpoint}/${productId}`, 'GET')
Get(inventoryId) {
return this.request.send(`${this.endpoint}/${inventoryId}`, 'GET')
}

Create(body) {
Create(body, productId) {
return this.request.send(`${this.endpoint}}`, 'POST', {
type: 'stock',
id: productId,
attributes: body
})
}

Delete(productId) {
return this.request.send(`${this.endpoint}/${productId}`, 'DELETE')
Update(inventoryId, body) {
return this.request.send(`${this.endpoint}/${inventoryId}`, 'PUT', {
type: 'stock',
id: inventoryId,
attributes: body
})
}

Delete(inventoryId) {
return this.request.send(`${this.endpoint}/${inventoryId}`, 'DELETE')
}

Limit(value) {
Expand Down
105 changes: 75 additions & 30 deletions src/types/multi-location-inventories.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,50 +4,81 @@
import { LocationsEndpoint } from './mli-locations'
import { Identifiable, Resource, ResourcePage } from './core'

type StockType = 'stock'
/**
* Multi Location Inventory Types
*/
export type InventoryResourceType = 'stock'

export interface StockMeta {
timestamps: {
created_at: string
updated_at: string
}
/**
* Base Types
*/
export interface Timestamps {
created_at: string
updated_at: string
}

/**
* Location-specific inventory quantities
*/
export interface LocationQuantities {
available: number
allocated: number
total: number
}

/**
* Create Operation Types
*/
export interface LocationCreateQuantity {
available: number
}

export interface StockBaseLocations {
[key: string]: {
available: number
export interface StockCreate {
available?: number
locations?: {
[locationId: string]: LocationCreateQuantity
}
}

export interface StockBaseAttributes {
product_id: string
locations: StockBaseLocations
/**
* Update Operation Types
*/
export interface LocationUpdateQuantity {
allocated?: number
available?: number
}

export interface StockResponseLocations {
[key: string]: {
available: number
allocated: number
total: number
export interface StockUpdate {
locations?: {
[locationId: string]: LocationUpdateQuantity | null
}
}
export interface StockResponseAttributes extends StockBaseAttributes {

/**
* Response Types
*/
export interface StockLocationsMap {
[locationId: string]: LocationQuantities
}

export interface StockAttributes {
allocated: number
available: number
total: number
locations: StockResponseLocations
locations: StockLocationsMap
}

export interface StockResponse extends Identifiable, StockMeta {
type: StockType
attributes: StockResponseAttributes
export interface StockResponse extends Identifiable {
type: InventoryResourceType
attributes: StockAttributes
timestamps: Timestamps
}

/**
* Multi Location Inventories Endpoints
* Multi Location Inventories Endpoint Interface
*/
export interface MultiLocationInventoriesEndpoint {
endpoint: 'inventory'

Locations: LocationsEndpoint

/**
Expand All @@ -57,21 +88,35 @@ export interface MultiLocationInventoriesEndpoint {

/**
* Get Stock for Product
* @param productId The ID of the product.
* @param inventoryId - The inventory identifier
*/
Get(productId: string): Promise<Resource<StockResponse>>
Get(inventoryId: string): Promise<Resource<StockResponse>>

/**
* Create Stock for Product
* @param body - The base attributes of the inventory stock.
* @param payload - Initial stock information with overall availability or per-location quantities
* @param productId - Optional product identifier
*/
Create(
payload: StockCreate,
productId?: string
): Promise<Resource<StockResponse>>

/**
* Update Stock for Product
* @param inventoryId - The inventory identifier
* @param payload - Location-specific updates. Set location to null to remove it
*/
Create(body: StockBaseAttributes): Promise<Resource<StockResponse>>
Update(
inventoryId: string,
payload: StockUpdate
): Promise<Resource<StockResponse>>

/**
* Delete Stock for Product
* @param productId The ID of the product.
* @param inventoryId - The inventory identifier
*/
Delete(productId: string): Promise<{}>
Delete(inventoryId: string): Promise<{}>

Limit(value: number): MultiLocationInventoriesEndpoint

Expand Down

0 comments on commit fe64e57

Please sign in to comment.