Skip to content

Commit

Permalink
feat: complete MLI endpoints (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
samblacklock authored Jan 29, 2025
1 parent 6fe6876 commit db9a51c
Show file tree
Hide file tree
Showing 2 changed files with 202 additions and 1 deletion.
101 changes: 101 additions & 0 deletions src/endpoints/multi-location-inventories.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,107 @@ class MultiLocationInventories {
this.filter = filter
return this
}

// Transactions endpoints

IncrementStock(productId, quantity, location = null) {
return this.request.send(
`${this.endpoint}/${productId}/transactions`,
'POST',
{
attributes: {
type: 'stock-transaction',
action: 'increment',
quantity,
product_id: productId,
...(location && { location })
}
}
)
}

DecrementStock(productId, quantity, location = null) {
return this.request.send(
`${this.endpoint}/${productId}/transactions`,
'POST',
{
attributes: {
type: 'stock-transaction',
action: 'decrement',
quantity,
product_id: productId,
...(location && { location })
}
}
)
}

AllocateStock(productId, quantity, location = null) {
return this.request.send(
`${this.endpoint}/${productId}/transactions`,
'POST',
{
attributes: {
type: 'stock-transaction',
action: 'allocate',
quantity,
product_id: productId,
...(location && { location })
}
}
)
}

DeallocateStock(productId, quantity, location = null) {
return this.request.send(
`${this.endpoint}/${productId}/transactions`,
'POST',
{
attributes: {
type: 'stock-transaction',
action: 'deallocate',
quantity,
product_id: productId,
...(location && { location })
}
}
)
}

SetStock(productId, quantity, location = null) {
return this.request.send(
`${this.endpoint}/${productId}/transactions`,
'POST',
{
attributes: {
type: 'stock-transaction',
action: 'set',
quantity,
product_id: productId,
...(location && { location })
}
}
)
}

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

GetTransaction(productId, transactionId) {
return this.request.send(
`${this.endpoint}/${productId}/transactions/${transactionId}`,
'GET'
)
}

GetMultipleStock(productIds) {
const body = productIds.map(id => ({ id }))
return this.request.send(`${this.endpoint}/multiple`, 'POST', body)
}
}

export default MultiLocationInventories
102 changes: 101 additions & 1 deletion src/types/multi-location-inventories.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
* Multi Location Inventory
*/
import { LocationsEndpoint } from './mli-locations'
import { Identifiable, Resource, ResourcePage } from './core'
import { Identifiable, Resource, ResourceList, ResourcePage } from './core'
import { Inventory, InventoryActionTypes } from './inventory'
import { InventoryResponse } from './inventory'

/**
* Multi Location Inventory Types
Expand Down Expand Up @@ -80,6 +82,20 @@ export interface MultiLocationInventoryFilter {
}
}

export interface MultiLocationInventoryResponse extends Identifiable {
type: string
attributes: {
action: InventoryActionTypes
product_id: string
quantity: number
}
meta: {
timestamps: {
created_at: string
}
}
}

/**
* Multi Location Inventories Endpoint Interface
*/
Expand Down Expand Up @@ -129,4 +145,88 @@ export interface MultiLocationInventoriesEndpoint {
Offset(value: number): MultiLocationInventoriesEndpoint

Filter(filter: MultiLocationInventoryFilter): MultiLocationInventoriesEndpoint

/**
* Increment Stock
* @param productId The ID for the product you're performing this action on.
* @param quantity The amount of stock affected by this transaction.
* @param location The slug of the location that the transaction should act on.
*/
IncrementStock(
productId: string,
quantity: number,
location?: string
): Promise<Resource<MultiLocationInventoryResponse>>

/**
* Decrement Stock
* @param productId The ID for the product you're performing this action on.
* @param quantity The amount of stock affected by this transaction.
* @param location The slug of the location that the transaction should act on.
*/
DecrementStock(
productId: string,
quantity: number,
location?: string
): Promise<Resource<MultiLocationInventoryResponse>>

/**
* Allocate Stock
* @param productId The ID for the product you're performing this action on.
* @param quantity The amount of stock affected by this transaction.
* @param location The slug of the location that the transaction should act on.
*/
AllocateStock(
productId: string,
quantity: number,
location?: string
): Promise<Resource<MultiLocationInventoryResponse>>

/**
* Deallocate Stock
* @param productId The ID for the product you're performing this action on.
* @param quantity The amount of stock affected by this transaction.
* @param location The slug of the location that the transaction should act on.
*/
DeallocateStock(
productId: string,
quantity: number,
location?: string
): Promise<Resource<MultiLocationInventoryResponse>>

/**
* Set Stock
* @param productId The ID for the product you're performing this action on.
* @param quantity The amount of stock affected by this transaction.
* @param location The slug of the location that the transaction should act on.
*/
SetStock(
productId: string,
quantity: number,
location?: string
): Promise<Resource<MultiLocationInventoryResponse>>

/**
* Get Transactions
* @param productId The ID for the product you're performing this action on.
*/
GetTransactions(
productId: string
): Promise<ResourceList<MultiLocationInventoryResponse>>

/**
* Get Transaction
* @param productId The ID for the product you're performing this action on.
* @param transactionId The ID for the transaction created on the product.
*/
GetTransaction(
productId: string,
transactionId: string
): Promise<Resource<MultiLocationInventoryResponse>>

/**
* Get Stocks for Multiple Products
* @param productIds The array of unique identifier of the products.
*/
GetMultipleStock(productIds: string[]): Promise<ResourceList<StockResponse>>
}

0 comments on commit db9a51c

Please sign in to comment.