feat: make products server managed
CI / build-and-test (push) Canceled after 0s

This commit is contained in:
2026-10-20 23:55:40 +02:00
parent 0ca9f4d16a
commit e7f59f7583
14 changed files with 697 additions and 181 deletions
+19 -8
View File
@@ -116,13 +116,19 @@ export interface Product {
name: string;
category: string | null;
priceInCents: number;
/** Null when the terminal doesn't track stock for this product; can be negative */
/** Null when stock is not tracked for this product; can be negative */
stock: number | null;
lowStockThreshold: number | null;
/** The latest count, on the dashboard or a terminal; null when never counted */
countedAt: string | null;
/** When it was created or last changed */
reportedAt: string;
pendingAdjustments: StockAdjustment[];
/** Archived (deleted): hidden on the terminals */
archivedAt: string | null;
}
export type ProductFields = { name: string; category: string | null; priceInCents: number; lowStockThreshold: number | null };
export type NewStockAdjustment = { productId: string; type: StockAdjustmentType; quantity: number; note?: string };
export function getCookie(name: string): string | null {
@@ -346,12 +352,17 @@ export const stockApi = {
method: 'POST',
body: JSON.stringify({ adjustments }),
}),
cancel: (venueId: string, id: string) =>
api(`/venues/${venueId}/stock/adjustments/${id}/cancel`, { method: 'POST' }),
setLowStockThreshold: (venueId: string, productId: string, lowStockThreshold: number | null) =>
api(`/venues/${venueId}/stock/products/${encodeURIComponent(productId)}`, {
method: 'PUT',
body: JSON.stringify({ lowStockThreshold }),
/** [stock] is the starting count; null: not tracked */
createProduct: (venueId: string, product: ProductFields & { stock: number | null }) =>
api<Product>(`/venues/${venueId}/stock/products`, {
method: 'POST',
body: JSON.stringify(product),
}),
/** Only the fields that are sent change; archived: true deletes (hides) the product */
updateProduct: (venueId: string, productId: string, changes: Partial<ProductFields> & { archived?: boolean }) =>
api<Product>(`/venues/${venueId}/stock/products/${encodeURIComponent(productId)}`, {
method: 'PATCH',
body: JSON.stringify(changes),
}),
};