Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: complete MLI endpoints #48

Merged
merged 2 commits into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>>
}