u
This commit is contained in:
@@ -2,34 +2,42 @@ import { http, httpBinary, httpGetBinary } from './http.js';
|
||||
|
||||
export const category = {
|
||||
/** GET /api/category/tree → { languageId, tree, articles } (company from session) */
|
||||
// #region GET /api/category/tree — getTree
|
||||
getTree() {
|
||||
return http('/api/category/tree');
|
||||
},
|
||||
// #endregion
|
||||
|
||||
/**
|
||||
* GET /api/category/:id/articles → { articles: [...] }
|
||||
* Article rows: sku, name, net, taxRate, fullHash, thumbW, thumbH, thumbHash, childCount, …
|
||||
*/
|
||||
// #region GET /api/category/:id/articles — getArticles
|
||||
getArticles(categoryId) {
|
||||
return http(`/api/category/${categoryId}/articles`);
|
||||
},
|
||||
// #endregion
|
||||
|
||||
/** POST /api/category → 201 { category } */
|
||||
// #region POST /api/category — create
|
||||
create({ parentId, name }) {
|
||||
return http('/api/category', {
|
||||
method: 'POST',
|
||||
body: { parentId: Number(parentId), name },
|
||||
});
|
||||
},
|
||||
// #endregion
|
||||
|
||||
/**
|
||||
* DELETE /api/category/:id → 204
|
||||
* Query: ?recursive=true (cascades deletion of subcategories and articles)
|
||||
*/
|
||||
// #region DELETE /api/category/:id — delete
|
||||
delete(categoryId, { recursive = false } = {}) {
|
||||
const qs = recursive ? '?recursive=true' : '';
|
||||
return http(`/api/category/${categoryId}${qs}`, { method: 'DELETE' });
|
||||
},
|
||||
// #endregion
|
||||
|
||||
/**
|
||||
* PATCH /api/category/:id
|
||||
@@ -37,12 +45,14 @@ export const category = {
|
||||
* Empty name → 400 name is required.
|
||||
* → 200 { category: { id, name, slug } }
|
||||
*/
|
||||
// #region PATCH /api/category/:id — updateName
|
||||
updateName(categoryId, name) {
|
||||
return http(`/api/category/${categoryId}`, {
|
||||
method: 'PATCH',
|
||||
body: { name },
|
||||
});
|
||||
},
|
||||
// #endregion
|
||||
|
||||
/**
|
||||
* PUT /api/category/order
|
||||
@@ -51,24 +61,28 @@ export const category = {
|
||||
* set of parentId (same count, no foreign/duplicate ids) → 400 Invalid category order.
|
||||
* → 200 { categoryIds: number[] }
|
||||
*/
|
||||
// #region PUT /api/category/order — reorder
|
||||
reorder(parentId, categoryIds) {
|
||||
return http('/api/category/order', {
|
||||
method: 'PUT',
|
||||
body: { parentId, categoryIds },
|
||||
});
|
||||
},
|
||||
// #endregion
|
||||
|
||||
/**
|
||||
* PATCH /api/category/:id
|
||||
* Body: { parentId } — moves the category under a new parent.
|
||||
* → 200 { category: { id, parentId, sort } } (kein name/slug im Response)
|
||||
*/
|
||||
// #region PATCH /api/category/:id — move
|
||||
move(categoryId, parentId) {
|
||||
return http(`/api/category/${categoryId}`, {
|
||||
method: 'PATCH',
|
||||
body: { parentId },
|
||||
});
|
||||
},
|
||||
// #endregion
|
||||
|
||||
/**
|
||||
* PATCH /api/category/:id
|
||||
@@ -77,18 +91,21 @@ export const category = {
|
||||
*
|
||||
* PROPOSED — backend needs to implement this field.
|
||||
*/
|
||||
// #region PATCH /api/category/:id — updatePos
|
||||
updatePos(categoryId, pos) {
|
||||
return http(`/api/category/${categoryId}`, {
|
||||
method: 'PATCH',
|
||||
body: { pos },
|
||||
});
|
||||
},
|
||||
// #endregion
|
||||
|
||||
/**
|
||||
* POST /api/category/:id/image
|
||||
* Body: raw image bytes (Content-Type: image/webp)
|
||||
* → 201 { category: { id, fullHash, thumbW, thumbH, thumbHash } }
|
||||
*/
|
||||
// #region POST /api/category/:id/image — uploadImage
|
||||
uploadImage(categoryId, file) {
|
||||
return httpBinary(`/api/category/${categoryId}/image`, {
|
||||
method: 'POST',
|
||||
@@ -96,14 +113,17 @@ export const category = {
|
||||
body: file,
|
||||
});
|
||||
},
|
||||
// #endregion
|
||||
|
||||
/**
|
||||
* DELETE /api/category/:id/image
|
||||
* → 200 { category: { id, thumbW: null, thumbH: null, thumbHash: null } }
|
||||
*/
|
||||
// #region DELETE /api/category/:id/image — deleteImage
|
||||
deleteImage(categoryId) {
|
||||
return http(`/api/category/${categoryId}/image`, { method: 'DELETE' });
|
||||
},
|
||||
// #endregion
|
||||
|
||||
/**
|
||||
* GET /api/category/export.zip → application/zip (binary download)
|
||||
@@ -112,7 +132,9 @@ export const category = {
|
||||
* entry per category image (content-addressed, deduplicated).
|
||||
* Errors: 400 No company selected, 401, 403, 404 (JSON { error }).
|
||||
*/
|
||||
// #region GET /api/category/export.zip — exportZip
|
||||
exportZip() {
|
||||
return httpGetBinary('/api/category/export.zip');
|
||||
},
|
||||
// #endregion
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user