This commit is contained in:
seb
2026-10-10 00:39:23 +02:00
parent 2c36a705c4
commit ff54fe3a18
30 changed files with 2250 additions and 2256 deletions

51
src/api/supplier.js Normal file
View File

@@ -0,0 +1,51 @@
import { http } from './http.js';
/**
* Company-scoped suppliers / Lieferanten (selectedCompanyId from session).
* Shape: Supplier = { id, name, createdAt, updatedAt }
*/
export const supplier = {
/** GET /api/supplier → { suppliers: Supplier[] } */
list() {
return http('/api/supplier');
},
/**
* POST /api/supplier
* Body: { name } — empty name ⇒ 400 Name required.
* → 201 { supplier: Supplier }
*/
create(body) {
return http('/api/supplier', { method: 'POST', body });
},
/**
* PATCH /api/supplier/:id
* Body: { name } — empty name ⇒ 400 Name required.
* → 200 { supplier: Supplier }
*/
update(id, body) {
return http(`/api/supplier/${id}`, { method: 'PATCH', body });
},
/** DELETE /api/supplier/:id → 204 */
delete(id) {
return http(`/api/supplier/${id}`, { method: 'DELETE' });
},
/**
* GET /api/supplier/:id/articles?skus=...
* → 200 { articles: SupplierArticle[] }
*/
getArticles(id, skus) {
let query = '';
if (skus != null) {
const list = Array.isArray(skus) ? skus : [skus];
const filtered = list.map((s) => String(s).trim()).filter(Boolean);
if (filtered.length > 0) {
query = `?skus=${encodeURIComponent(filtered.join(','))}`;
}
}
return http(`/api/supplier/${encodeURIComponent(id)}/articles${query}`);
},
};