75 lines
1.9 KiB
JavaScript
75 lines
1.9 KiB
JavaScript
|
|
import { apiRequest, getPath } from './client.js';
|
||
|
|
|
||
|
|
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) {
|
||
|
|
const payload = await apiRequest(store, `${getPath('stockEntries')}/${stockId}`);
|
||
|
|
return payload?.data || payload?.entry || payload;
|
||
|
|
}
|
||
|
|
|
||
|
|
export async function createStockEntry(store, body) {
|
||
|
|
const payload = await apiRequest(store, getPath('items'), {
|
||
|
|
method: 'POST',
|
||
|
|
body,
|
||
|
|
includeKitchen: false,
|
||
|
|
query: { label: 1 },
|
||
|
|
});
|
||
|
|
return payload?.data || payload?.entry || payload;
|
||
|
|
}
|
||
|
|
|
||
|
|
export async function updateStockItem(store, uuidB64, body) {
|
||
|
|
const payload = await apiRequest(store, `${getPath('items')}/${uuidB64}/stock`, {
|
||
|
|
method: 'POST',
|
||
|
|
body,
|
||
|
|
includeKitchen: false,
|
||
|
|
});
|
||
|
|
return payload?.data || payload?.entry || payload;
|
||
|
|
}
|
||
|
|
|
||
|
|
export async function deleteStockItem(store, uuidB64) {
|
||
|
|
const payload = await apiRequest(store, `${getPath('items')}/${uuidB64}`, {
|
||
|
|
method: 'DELETE',
|
||
|
|
includeKitchen: false,
|
||
|
|
});
|
||
|
|
return payload?.data || payload?.entry || payload;
|
||
|
|
}
|
||
|
|
|
||
|
|
export async function adjustStockEntry(store, stockId, body) {
|
||
|
|
const payload = await apiRequest(
|
||
|
|
store,
|
||
|
|
`${getPath('stockEntries')}/${stockId}/adjust`,
|
||
|
|
{
|
||
|
|
method: 'POST',
|
||
|
|
body,
|
||
|
|
},
|
||
|
|
);
|
||
|
|
return payload?.data || payload?.entry || payload;
|
||
|
|
}
|