This commit is contained in:
seb
2026-10-04 21:04:40 +02:00
parent 669954b496
commit f765b87336
59 changed files with 1491 additions and 2045 deletions

View File

@@ -1,5 +1,7 @@
// Single source of truth for all backend communication.
import { requireArray, requireObject } from '../utils/apiShape';
/** WebView consoles stringify objects as [object Object]; log JSON text. */
function logApi(tag, details) {
let text;
@@ -195,6 +197,29 @@ export const articleIndex = {
list() {
return http('/api/articleIndex');
},
/**
* Fetches the company article index and maps backend rows to the recordset
* shape consumed by the search result list.
*
* `categories` becomes a comma-joined string because `formatCategoryList`
* splits on ','.
*
* @returns {Promise<Array<ArticleIndexRecord>>}
*/
async listRecords() {
const data = await http('/api/articleIndex');
requireObject(data, 'GET /api/articleIndex');
const articles = requireArray(data.articles, 'articleIndex.articles');
return articles.map((a) => ({
id: a.id,
sku: a.sku,
name: a.name,
eans: a.eans ?? [],
categories: Array.isArray(a.categoryIds) ? a.categoryIds.join(',') : null,
isFather: Boolean(a.isFather ?? a.is_father),
}));
},
};
export const article = {
@@ -337,6 +362,17 @@ export const article = {
});
},
/**
* PUT /api/article/:sku/weight
* Body: { weight } → 200 { article }
*/
setWeight(sku, body) {
return http(`/api/article/${encodeURIComponent(sku)}/weight`, {
method: 'PUT',
body,
});
},
/**
* PUT /api/article/:sku/brand
* Body: { brandId: number | null } — null clears the brand.
@@ -624,6 +660,46 @@ export const printer = {
delete(id) {
return http(`/api/printer/${id}`, { method: 'DELETE' });
},
/**
* PUT /api/printer/order
* Body: { printerIds: number[] }
* → 200 { printerIds: number[] }
*/
order({ printerIds }) {
return http('/api/printer/order', { method: 'PUT', body: { printerIds } });
},
};
/**
* Company-scoped key/value settings (selectedCompanyId from session).
* Shape: Setting = { key, value, frontend }
*/
export const setting = {
/**
* GET /api/company/setting
* Optional query: { frontendOnly } → 200 { settings: Setting[] }
*/
list({ frontendOnly } = {}) {
const qs = frontendOnly ? '?frontendOnly=1' : '';
return http(`/api/company/setting${qs}`);
},
/** GET /api/company/setting/:key → { setting: Setting } */
get(key) {
return http(`/api/company/setting/${encodeURIComponent(key)}`);
},
/**
* PUT /api/company/setting/:key
* Body: { value, frontend } → 200 { setting: Setting }
*/
upsert(key, body) {
return http(`/api/company/setting/${encodeURIComponent(key)}`, {
method: 'PUT',
body,
});
},
};
/**
@@ -1912,6 +1988,7 @@ export default {
printer,
propertyname,
quote,
setting,
supplier,
thumb,
unit,