u
This commit is contained in:
@@ -103,6 +103,8 @@ export class ApiClient {
|
||||
create: (body) => this.#json('POST', '/api/warehouse', { body }),
|
||||
/** PATCH /api/warehouse/{id} → 200 { warehouse: Warehouse } */
|
||||
update: (id, body) => this.#json('PATCH', `/api/warehouse/${enc(id)}`, { body }),
|
||||
/** PUT /api/warehouse/order → 200 { warehouseIds: number[] } */
|
||||
order: (body) => this.#json('PUT', '/api/warehouse/order', { body }),
|
||||
/** DELETE /api/warehouse/{id} → 204 */
|
||||
delete: (id) => this.#empty('DELETE', `/api/warehouse/${enc(id)}`),
|
||||
};
|
||||
@@ -353,7 +355,7 @@ export class ApiClient {
|
||||
* `onHistory(history, total)` — returns `{ unwatch, setSkipAndOffset }`.
|
||||
*/
|
||||
historyWatch: (sku, onHistory) => this.watchArticleHistory(sku, onHistory),
|
||||
/** PATCH /api/article/{sku} — body: at least one of { name, unitamount, unitSi } */
|
||||
/** PATCH /api/article/{sku} — body: at least one of { name, unitamount, unitSi, track_stock } */
|
||||
update: async (sku, body) => {
|
||||
const nameChange = body != null && Object.hasOwn(body, 'name');
|
||||
if (nameChange) {
|
||||
@@ -400,6 +402,15 @@ export class ApiClient {
|
||||
/** PUT /api/article/{sku}/categories */
|
||||
setCategories: (sku, body) =>
|
||||
this.#json('PUT', `/api/article/${enc(sku)}/categories`, { body }),
|
||||
/** PUT /api/article/{sku}/track_stock */
|
||||
setTrackStock: async (sku, body) => {
|
||||
const payload = typeof body === 'boolean' ? { track_stock: body } : body;
|
||||
const res = await this.#json('PUT', `/api/article/${enc(sku)}/track_stock`, { body: payload });
|
||||
if (res?.article) {
|
||||
this.setArticle(res.article);
|
||||
}
|
||||
return res;
|
||||
},
|
||||
/** GET /api/article/{sku}/supplier */
|
||||
getSuppliers: (sku) => this.#json('GET', `/api/article/${enc(sku)}/supplier`),
|
||||
/** POST /api/article/{sku}/supplier */
|
||||
|
||||
129
src/api/index.js
129
src/api/index.js
@@ -216,16 +216,20 @@ export const article = {
|
||||
},
|
||||
|
||||
/** POST /api/article → 201 { article } */
|
||||
create({ parentId, name }) {
|
||||
create({ parentId, name, track_stock }) {
|
||||
return http('/api/article', {
|
||||
method: 'POST',
|
||||
body: { parentId, name },
|
||||
body: {
|
||||
parentId,
|
||||
name,
|
||||
...(track_stock !== undefined ? { track_stock } : {}),
|
||||
},
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* PATCH /api/article/:sku
|
||||
* Body: at least one of { name, unitamount, unitSi }
|
||||
* Body: at least one of { name, unitamount, unitSi, track_stock }
|
||||
* unitSi must exist for selected company → 404 Unit not found
|
||||
* → 200 { article } (same detail shape as GET)
|
||||
*/
|
||||
@@ -236,6 +240,19 @@ export const article = {
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* PUT /api/article/:sku/track_stock
|
||||
* Body: { track_stock: boolean }
|
||||
* → 200 { article }
|
||||
*/
|
||||
setTrackStock(sku, body) {
|
||||
const payload = typeof body === 'boolean' ? { track_stock: body } : body;
|
||||
return http(`/api/article/${encodeURIComponent(sku)}/track_stock`, {
|
||||
method: 'PUT',
|
||||
body: payload,
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* DELETE /api/article/:sku → 204
|
||||
* Errors: 400 Article has children, 401, 403, 404 Article not found
|
||||
@@ -404,6 +421,56 @@ export const article = {
|
||||
const qs = params.toString();
|
||||
return httpGetBinary(`/api/article/export.zip${qs ? `?${qs}` : ''}`);
|
||||
},
|
||||
/**
|
||||
* POST /api/article/:sku/print
|
||||
* Body: { printerId, templateId, quantity }
|
||||
* Prints the given template to the specified printer for this article.
|
||||
*/
|
||||
printLabel(sku, body) {
|
||||
return http(`/api/article/${encodeURIComponent(sku)}/print`, {
|
||||
method: 'POST',
|
||||
body,
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
* Company-scoped printers (selectedCompanyId from session).
|
||||
* Shape: Printer = { id, address, type, model, serial, sort, desc }
|
||||
*/
|
||||
export const printer = {
|
||||
/** GET /api/printer → { printers: Printer[] } */
|
||||
list() {
|
||||
return http('/api/printer');
|
||||
},
|
||||
|
||||
/** GET /api/printer/:id → { printer: Printer } */
|
||||
getById(id) {
|
||||
return http(`/api/printer/${id}`);
|
||||
},
|
||||
|
||||
/**
|
||||
* POST /api/printer
|
||||
* Body: { address, type, model, serial, sort, desc }
|
||||
* → 201 { printer: Printer }
|
||||
*/
|
||||
create(body) {
|
||||
return http('/api/printer', { method: 'POST', body });
|
||||
},
|
||||
|
||||
/**
|
||||
* PATCH /api/printer/:id
|
||||
* Body: partial printer fields
|
||||
* → 200 { printer: Printer }
|
||||
*/
|
||||
update(id, body) {
|
||||
return http(`/api/printer/${id}`, { method: 'PATCH', body });
|
||||
},
|
||||
|
||||
/** DELETE /api/printer/:id → 204 */
|
||||
delete(id) {
|
||||
return http(`/api/printer/${id}`, { method: 'DELETE' });
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -679,7 +746,7 @@ export const warehouse = {
|
||||
|
||||
/**
|
||||
* POST /api/warehouse
|
||||
* Body: { name } — empty name ⇒ 400 Name required.
|
||||
* Body: { name, sort? } — empty name ⇒ 400 Name required.
|
||||
* → 201 { warehouse: Warehouse }
|
||||
*/
|
||||
create(body) {
|
||||
@@ -688,13 +755,22 @@ export const warehouse = {
|
||||
|
||||
/**
|
||||
* PATCH /api/warehouse/:id
|
||||
* Body: { name } — empty name ⇒ 400 Name required.
|
||||
* Body: { name?, sort? }
|
||||
* → 200 { warehouse: Warehouse }
|
||||
*/
|
||||
update(id, body) {
|
||||
return http(`/api/warehouse/${id}`, { method: 'PATCH', body });
|
||||
},
|
||||
|
||||
/**
|
||||
* PUT /api/warehouse/order
|
||||
* Body: { warehouseIds: number[] }
|
||||
* → 200 { warehouseIds: number[] }
|
||||
*/
|
||||
order(body) {
|
||||
return http('/api/warehouse/order', { method: 'PUT', body });
|
||||
},
|
||||
|
||||
/** DELETE /api/warehouse/:id → 204 */
|
||||
delete(id) {
|
||||
return http(`/api/warehouse/${id}`, { method: 'DELETE' });
|
||||
@@ -1466,6 +1542,47 @@ export const auth = {
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
* Company-scoped ZPL label templates (selectedCompanyId from session).
|
||||
* Shape: LabelTemplate = { id, company_id, name, width, height, dpi, type, content, thumb }
|
||||
*/
|
||||
export const labeltemplate = {
|
||||
/** GET /api/labeltemplate → { labeltemplates: LabelTemplate[] } */
|
||||
list() {
|
||||
return http('/api/labeltemplate');
|
||||
},
|
||||
|
||||
/** GET /api/labeltemplate/:id → { labeltemplate: LabelTemplate } */
|
||||
get(id) {
|
||||
return http(`/api/labeltemplate/${encodeURIComponent(id)}`);
|
||||
},
|
||||
|
||||
/**
|
||||
* POST /api/labeltemplate
|
||||
* Body: { name, width, height, dpi, type, content }
|
||||
* → 201 { labeltemplate: LabelTemplate }
|
||||
*/
|
||||
create(body) {
|
||||
return http('/api/labeltemplate', { method: 'POST', body });
|
||||
},
|
||||
|
||||
/**
|
||||
* PATCH /api/labeltemplate/:id
|
||||
* Body: partial { name?, width?, height?, dpi?, type?, content? }
|
||||
* → 200 { labeltemplate: LabelTemplate }
|
||||
*/
|
||||
update(id, body) {
|
||||
return http(`/api/labeltemplate/${encodeURIComponent(id)}`, { method: 'PATCH', body });
|
||||
},
|
||||
|
||||
/** DELETE /api/labeltemplate/:id → 204 */
|
||||
delete(id) {
|
||||
return http(`/api/labeltemplate/${encodeURIComponent(id)}`, { method: 'DELETE' });
|
||||
},
|
||||
|
||||
// thumb is returned inline as a base64 string in list/get responses
|
||||
};
|
||||
|
||||
export default {
|
||||
auth,
|
||||
article,
|
||||
@@ -1476,10 +1593,12 @@ export default {
|
||||
customergroup,
|
||||
delivery,
|
||||
entity,
|
||||
labeltemplate,
|
||||
ledger,
|
||||
number,
|
||||
order,
|
||||
posterminal,
|
||||
printer,
|
||||
quote,
|
||||
supplier,
|
||||
thumb,
|
||||
|
||||
Reference in New Issue
Block a user