bulk request
This commit is contained in:
@@ -40,6 +40,18 @@ export interface StockRequestQuery {
|
||||
pagesize?: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* What a batch actually did.
|
||||
*
|
||||
* Both lists are always read: a batch that half-worked is the case worth
|
||||
* reporting, and the failures name the row so somebody can go and look.
|
||||
*/
|
||||
export interface StockBatchOutcome {
|
||||
updated?: number[];
|
||||
created?: unknown[];
|
||||
failed?: { requestid?: number; productid?: number; reason: string }[];
|
||||
}
|
||||
|
||||
export interface CreateStockRequest {
|
||||
tenantid: number;
|
||||
locationid: number;
|
||||
@@ -92,6 +104,35 @@ export const stockApi = {
|
||||
status: STOCK_REQUEST_STATUS.received,
|
||||
}),
|
||||
|
||||
/**
|
||||
* Several requests at once.
|
||||
*
|
||||
* One call rather than a loop of them, because approving MOVES STOCK: a loop
|
||||
* that dies halfway leaves some deliveries received and some not, with nothing
|
||||
* to say which. The backend applies each id separately and reports both lists,
|
||||
* so a partial outcome is a fact the screen can show rather than a guess.
|
||||
*
|
||||
* The same status for the whole batch, never a mix. "Approve these" and
|
||||
* "reject these" are two decisions, and one call that could do both is how a
|
||||
* mis-click approves what it meant to refuse.
|
||||
*/
|
||||
decideMany: (requestids: number[], status: StockRequestStatus) =>
|
||||
api.put<StockBatchOutcome>(`${WEB}/products/updatestockrequest`, { requestids, status }),
|
||||
|
||||
approveMany: (requestids: number[]) => stockApi.decideMany(requestids, STOCK_REQUEST_STATUS.received),
|
||||
rejectMany: (requestids: number[]) => stockApi.decideMany(requestids, STOCK_REQUEST_STATUS.rejected),
|
||||
|
||||
/**
|
||||
* A branch asks for several products in one go.
|
||||
*
|
||||
* Restocking after a delivery is one errand, not twenty. Sending it as twenty
|
||||
* calls is slow, and a dropped connection leaves a half-made request list that
|
||||
* nobody can tell apart from a deliberate one.
|
||||
*/
|
||||
createMany: (rows: CreateStockRequest[]) =>
|
||||
api.post<StockBatchOutcome>(`${WEB}/products/createstockrequest`,
|
||||
rows.map((row) => ({ ...row, status: STOCK_REQUEST_STATUS.pending }))),
|
||||
|
||||
/** Reject — a status write and nothing else. No stock moves, no reason stored. */
|
||||
reject: (requestid: number) =>
|
||||
api.put<unknown>(`${WEB}/products/updatestockrequest`, {
|
||||
|
||||
Reference in New Issue
Block a user