Return explicit errors for unsupported POS workflows
This commit is contained in:
@@ -30,6 +30,7 @@ import {
|
||||
inventoryAdjust,
|
||||
listInventoryItems,
|
||||
listInventoryWithTransactions,
|
||||
recordWastage,
|
||||
stockIn,
|
||||
stocktake as stocktakeInventory,
|
||||
stockOut,
|
||||
@@ -337,6 +338,40 @@ function unsupportedPaymentAdapter(method: unknown) {
|
||||
return !["cash", "customer_order", "kitchen_order", "room_fnb"].includes(normalized);
|
||||
}
|
||||
|
||||
function statusForServiceError(error: unknown) {
|
||||
const message = error instanceof Error ? error.message : "BFF request failed";
|
||||
if (/not configured|requires persisted|requires a configured/i.test(message)) return 501;
|
||||
if (/insufficient inventory|insufficient stock/i.test(message)) return 409;
|
||||
if (/not found/i.test(message)) return 404;
|
||||
return 400;
|
||||
}
|
||||
|
||||
function unsupportedWorkflow(path: string[]) {
|
||||
const key = path.join("/");
|
||||
const unsupported = new Map<string, string>([
|
||||
["inventory/stock-transfer", "Stock transfer requires multi-location inventory ledger support before it can be executed."],
|
||||
["orders/split-bill", "Split bill requires persisted split payment ledger support before it can be executed."],
|
||||
["orders/cash-drawer", "Cash drawer requires persisted cash session ledger support before it can be executed."],
|
||||
["orders/tip", "Tip requires persisted gratuity ledger support before it can be executed."],
|
||||
["orders/refund", "Refund requires persisted refund ledger support before it can be executed."],
|
||||
["orders/void", "Void requires persisted refund/void ledger support before it can be executed."],
|
||||
["pos/stock-transfer", "Stock transfer requires multi-location inventory ledger support before it can be executed."],
|
||||
["pos/split-bill", "Split bill requires persisted split payment ledger support before it can be executed."],
|
||||
["pos/cash-drawer", "Cash drawer requires persisted cash session ledger support before it can be executed."],
|
||||
["pos/tip", "Tip requires persisted gratuity ledger support before it can be executed."],
|
||||
["pos/refund", "Refund requires persisted refund ledger support before it can be executed."],
|
||||
["pos/void", "Void requires persisted refund/void ledger support before it can be executed."]
|
||||
]);
|
||||
if (unsupported.has(key)) return unsupported.get(key);
|
||||
if (path[0] === "orders" && path[2] === "refund") return "Refund requires persisted refund ledger support before it can be executed.";
|
||||
if (path[0] === "orders" && path[2] === "void") return "Void requires persisted refund/void ledger support before it can be executed.";
|
||||
if (path[0] === "orders" && path[2] === "split-bill") return "Split bill requires persisted split payment ledger support before it can be executed.";
|
||||
if (path[0] === "orders" && path[2] === "tip") return "Tip requires persisted gratuity ledger support before it can be executed.";
|
||||
if (path[0] === "orders" && path[2] === "edit") return "Order edit requires persisted order revision support before it can be executed.";
|
||||
if (path[0] === "orders" && path[2] === "receipt") return "Receipt rendering is read-only in MVP and must use GET order detail.";
|
||||
return null;
|
||||
}
|
||||
|
||||
function requiredShopId(value: unknown) {
|
||||
const shopId = stringValue(value);
|
||||
return shopId ? { shopId } : { error: fail("shopId is required", { status: 400 }) };
|
||||
|
||||
Reference in New Issue
Block a user