u
This commit is contained in:
51
src/api/supplier.js
Normal file
51
src/api/supplier.js
Normal 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}`);
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user