59 lines
1.8 KiB
TypeScript
59 lines
1.8 KiB
TypeScript
import { api } from '@/lib/api'
|
|
import type {
|
|
PaginatedResponse,
|
|
StockBalanceResponse,
|
|
StockMovementResponse,
|
|
LowStockItemResponse,
|
|
LocationType,
|
|
MovementType,
|
|
} from '@/types/api'
|
|
|
|
import type { PageParams } from './master'
|
|
|
|
export interface StockBalanceParams extends PageParams {
|
|
locationId?: string
|
|
locationType?: LocationType
|
|
itemId?: string
|
|
}
|
|
|
|
export interface StockMovementParams extends PageParams {
|
|
itemId?: string
|
|
locationId?: string
|
|
type?: MovementType
|
|
from?: string
|
|
to?: string
|
|
}
|
|
|
|
export interface AdjustmentBody {
|
|
itemId: string
|
|
locationId: string
|
|
locationType: LocationType
|
|
quantity: number
|
|
reasonCode: string
|
|
// TEMPORARY: required while auth doesn't resolve a logged-in user server-side — see testbug.md #28.
|
|
adjustedByUserId: string
|
|
}
|
|
|
|
export const stock = {
|
|
balances: (params?: StockBalanceParams) =>
|
|
api.get<PaginatedResponse<StockBalanceResponse>>('/stock/balances', { params }).then(r => r.data),
|
|
|
|
movements: (params?: StockMovementParams) =>
|
|
api.get<PaginatedResponse<StockMovementResponse>>('/stock/movements', { params }).then(r => r.data),
|
|
|
|
lowStock: (locationId?: string) =>
|
|
api.get<LowStockItemResponse[]>('/stock/low-stock', { params: { locationId } }).then(r => r.data),
|
|
|
|
adjust: (body: AdjustmentBody) =>
|
|
api.post('/stock/adjustment', body).then(r => r.data),
|
|
|
|
/** Next free number for auto-generated serials: one past the highest `<prefix><digits>` already saved for the item. */
|
|
nextSerialSequence: (itemId: string, prefix: string) =>
|
|
api
|
|
.get<{ next: number }>('/stock/serials/next-sequence', { params: { itemId, prefix } })
|
|
.then(r => r.data.next),
|
|
|
|
updateMovementReason: (id: string, reasonCode: string) =>
|
|
api.patch(`/stock/movements/${id}/reason`, { reasonCode }).then(r => r.data),
|
|
}
|