pick orders
This commit is contained in:
@@ -5,7 +5,7 @@ import { z } from "zod";
|
||||
|
||||
import { fail, ok } from "../../lib/http.js";
|
||||
import { requirePermissions } from "../../lib/rbac.js";
|
||||
import { createShipment, getShipmentById, listShipmentOrderOptions, listShipments, updateShipment, updateShipmentStatus } from "./service.js";
|
||||
import { createShipment, getShipmentById, listShipmentOrderOptions, listShipments, postShipmentPick, updateShipment, updateShipmentStatus } from "./service.js";
|
||||
|
||||
const shipmentSchema = z.object({
|
||||
salesOrderId: z.string().trim().min(1),
|
||||
@@ -28,6 +28,14 @@ const shipmentStatusUpdateSchema = z.object({
|
||||
status: z.enum(shipmentStatuses),
|
||||
});
|
||||
|
||||
const shipmentPickSchema = z.object({
|
||||
salesOrderLineId: z.string().trim().min(1),
|
||||
warehouseId: z.string().trim().min(1),
|
||||
locationId: z.string().trim().min(1),
|
||||
quantity: z.number().positive(),
|
||||
notes: z.string(),
|
||||
});
|
||||
|
||||
function getRouteParam(value: unknown) {
|
||||
return typeof value === "string" ? value : null;
|
||||
}
|
||||
@@ -112,3 +120,22 @@ shippingRouter.patch("/shipments/:shipmentId/status", requirePermissions([permis
|
||||
|
||||
return ok(response, result.shipment);
|
||||
});
|
||||
|
||||
shippingRouter.post("/shipments/:shipmentId/picks", requirePermissions([permissions.shippingWrite]), async (request, response) => {
|
||||
const shipmentId = getRouteParam(request.params.shipmentId);
|
||||
if (!shipmentId) {
|
||||
return fail(response, 400, "INVALID_INPUT", "Shipment id is invalid.");
|
||||
}
|
||||
|
||||
const parsed = shipmentPickSchema.safeParse(request.body);
|
||||
if (!parsed.success) {
|
||||
return fail(response, 400, "INVALID_INPUT", "Shipment pick payload is invalid.");
|
||||
}
|
||||
|
||||
const result = await postShipmentPick(shipmentId, parsed.data, request.authUser?.id);
|
||||
if (!result.ok) {
|
||||
return fail(response, 400, "INVALID_INPUT", result.reason);
|
||||
}
|
||||
|
||||
return ok(response, result.shipment, 201);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user