2026-04-06 09:24:22 +02:00
|
|
|
import { apiRequest, getPath } from './client.js';
|
|
|
|
|
|
2026-04-06 10:30:37 +02:00
|
|
|
function unwrapEntryPayload(payload) {
|
|
|
|
|
return payload?.data || payload?.entry || payload?.item || payload;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-06 09:24:22 +02:00
|
|
|
export async function searchItemDefinitions(store, query) {
|
|
|
|
|
if (query.trim().length <= 2) {
|
|
|
|
|
return [];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const payload = await apiRequest(store, getPath('items'), {
|
|
|
|
|
includeKitchen: false,
|
|
|
|
|
query: { search_name: query },
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (Array.isArray(payload)) {
|
|
|
|
|
return payload;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return payload?.data || payload?.items || [];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function listStockEntries(store, filters = {}) {
|
|
|
|
|
const payload = await apiRequest(store, getPath('items'), {
|
|
|
|
|
includeKitchen: false,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (Array.isArray(payload)) {
|
|
|
|
|
return payload;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return payload?.data || payload?.entries || payload?.items || [];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function getStockEntry(store, stockId) {
|
2026-04-06 10:30:37 +02:00
|
|
|
const payload = await apiRequest(store, `${getPath('items')}/${stockId}`, {
|
|
|
|
|
includeKitchen: false,
|
|
|
|
|
});
|
|
|
|
|
return unwrapEntryPayload(payload);
|
2026-04-06 09:24:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function createStockEntry(store, body) {
|
|
|
|
|
const payload = await apiRequest(store, getPath('items'), {
|
|
|
|
|
method: 'POST',
|
|
|
|
|
body,
|
|
|
|
|
includeKitchen: false,
|
|
|
|
|
query: { label: 1 },
|
|
|
|
|
});
|
2026-04-06 10:30:37 +02:00
|
|
|
return unwrapEntryPayload(payload);
|
2026-04-06 09:24:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function updateStockItem(store, uuidB64, body) {
|
|
|
|
|
const payload = await apiRequest(store, `${getPath('items')}/${uuidB64}/stock`, {
|
|
|
|
|
method: 'POST',
|
|
|
|
|
body,
|
|
|
|
|
includeKitchen: false,
|
|
|
|
|
});
|
2026-04-06 10:30:37 +02:00
|
|
|
return unwrapEntryPayload(payload);
|
2026-04-06 09:24:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function deleteStockItem(store, uuidB64) {
|
|
|
|
|
const payload = await apiRequest(store, `${getPath('items')}/${uuidB64}`, {
|
|
|
|
|
method: 'DELETE',
|
|
|
|
|
includeKitchen: false,
|
|
|
|
|
});
|
2026-04-06 10:30:37 +02:00
|
|
|
return unwrapEntryPayload(payload);
|
2026-04-06 09:24:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function adjustStockEntry(store, stockId, body) {
|
2026-04-06 10:30:37 +02:00
|
|
|
const payload = await apiRequest(store, `${getPath('items')}/${stockId}/stock`, {
|
|
|
|
|
method: 'POST',
|
|
|
|
|
body,
|
|
|
|
|
includeKitchen: false,
|
|
|
|
|
});
|
|
|
|
|
return unwrapEntryPayload(payload);
|
2026-04-06 09:24:22 +02:00
|
|
|
}
|