u
This commit is contained in:
@@ -2,42 +2,52 @@ import { http } from './http.js';
|
||||
|
||||
export const company = {
|
||||
/** GET /api/company → { companies: [...] } */
|
||||
// #region GET /api/company — list
|
||||
list() {
|
||||
return http('/api/company');
|
||||
},
|
||||
// #endregion
|
||||
|
||||
/** Uses GET /api/company until a dedicated endpoint exists. */
|
||||
// #region GET /api/company — getById
|
||||
async getById(companyId) {
|
||||
const data = await http('/api/company');
|
||||
const found = data.companies?.find((item) => item.id === companyId);
|
||||
if (!found) throw new Error('Unternehmen nicht gefunden.');
|
||||
return { company: found };
|
||||
},
|
||||
// #endregion
|
||||
|
||||
// #region POST /api/company — create
|
||||
create({ name, iso639, taxrate, reducedtaxrate }) {
|
||||
return http('/api/company', {
|
||||
method: 'POST',
|
||||
body: { name, iso639, taxrate, reducedtaxrate },
|
||||
});
|
||||
},
|
||||
// #endregion
|
||||
|
||||
/**
|
||||
* PUT /api/company/:companyId
|
||||
* Body: { name, iso639, taxrate, reducedtaxrate }
|
||||
*/
|
||||
// #region PUT /api/company/:companyId — update
|
||||
update(companyId, { name, iso639, taxrate, reducedtaxrate }) {
|
||||
return http(`/api/company/${companyId}`, {
|
||||
method: 'PUT',
|
||||
body: { name, iso639, taxrate, reducedtaxrate },
|
||||
});
|
||||
},
|
||||
// #endregion
|
||||
|
||||
// #region PUT /api/auth/selected-company — select
|
||||
select(companyId) {
|
||||
return http('/api/auth/selected-company', {
|
||||
method: 'PUT',
|
||||
body: { companyId },
|
||||
});
|
||||
},
|
||||
// #endregion
|
||||
|
||||
/**
|
||||
* POST /api/company/import
|
||||
@@ -48,12 +58,14 @@ export const company = {
|
||||
* @param {object} [callbacks]
|
||||
* @param {(progress: { loaded: number, total: number, percent: number }) => void} [callbacks.onUploadProgress]
|
||||
* @param {(message: string) => void} [callbacks.onStatus]
|
||||
* @param {(progress: { phase: string, current: number, total: number, item?: string }) => void} [callbacks.onProgress]
|
||||
* @param {(progress: { categoriestotal: number, categoriesdone: number, articlestotal: number, articlesdone: number, imagestotal: number, imagesdone: number, receiptstotal: number, receiptsdone: number }) => void} [callbacks.onProgress] Counter-based progress snapshot across all phases.
|
||||
* @param {(images: string[]) => void} [callbacks.onImages] Batched `images` events (~every 100ms) carrying Base62 SkeleHash strings.
|
||||
* @param {(stats: object) => void} [callbacks.onDone]
|
||||
* @param {(error: string) => void} [callbacks.onError]
|
||||
* @param {object} [options]
|
||||
* @param {AbortSignal} [options.signal]
|
||||
*/
|
||||
// #region POST /api/company/import — importCatalog
|
||||
importCatalog(file, callbacks = {}, { signal } = {}) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const xhr = new XMLHttpRequest();
|
||||
@@ -122,6 +134,21 @@ export const company = {
|
||||
case 'progress':
|
||||
callbacks.onProgress?.(eventData);
|
||||
break;
|
||||
case 'images': {
|
||||
// Payload is a plain array of Base62 SkeleHash strings;
|
||||
// also tolerate the { images: [...] } wrapper shape.
|
||||
const list = Array.isArray(eventData)
|
||||
? eventData
|
||||
: Array.isArray(eventData?.images)
|
||||
? eventData.images
|
||||
: [];
|
||||
if (list.length) callbacks.onImages?.(list);
|
||||
break;
|
||||
}
|
||||
case 'image':
|
||||
// Legacy: single image event (pre-batching).
|
||||
if (eventData) callbacks.onImages?.([eventData]);
|
||||
break;
|
||||
case 'done':
|
||||
callbacks.onDone?.(eventData?.stats ?? eventData);
|
||||
break;
|
||||
@@ -165,4 +192,5 @@ export const company = {
|
||||
xhr.send(formData);
|
||||
});
|
||||
},
|
||||
// #endregion
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user