Files
dashfront/src/api/supplier.js
2026-10-18 00:38:45 +02:00

69 lines
1.8 KiB
JavaScript

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[] } */
// #region GET /api/supplier — list
list() {
return http('/api/supplier');
},
// #endregion
/** GET /api/supplier/:id → { supplier: Supplier } */
// #region GET /api/supplier/:id — get
get(id) {
return http(`/api/supplier/${encodeURIComponent(id)}`);
},
// #endregion
/**
* POST /api/supplier
* Body: { name } — empty name ⇒ 400 Name required.
* → 201 { supplier: Supplier }
*/
// #region POST /api/supplier — create
create(body) {
return http('/api/supplier', { method: 'POST', body });
},
// #endregion
/**
* PATCH /api/supplier/:id
* Body: { name } — empty name ⇒ 400 Name required.
* → 200 { supplier: Supplier }
*/
// #region PATCH /api/supplier/:id — update
update(id, body) {
return http(`/api/supplier/${id}`, { method: 'PATCH', body });
},
// #endregion
/** DELETE /api/supplier/:id → 204 */
// #region DELETE /api/supplier/:id — delete
delete(id) {
return http(`/api/supplier/${id}`, { method: 'DELETE' });
},
// #endregion
/**
* GET /api/supplier/:id/articles?skus=...
* → 200 { articles: SupplierArticle[] }
*/
// #region GET /api/supplier/:id/articles — getArticles
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}`);
},
// #endregion
};