This commit is contained in:
seb
2026-08-07 03:52:11 +02:00
parent 628980dc49
commit 83ac0efd00
3 changed files with 149 additions and 64 deletions

View File

@@ -122,13 +122,15 @@ export class ApiClient {
};
this.customergroup = {
/** GET /api/customergroup → { customergroups } */
/** GET /api/customergroup → { customergroups: { id, name, sort, editable }[] } */
list: () => this.#json('GET', '/api/customergroup'),
/** POST /api/customergroup → 201 { customergroup } */
/** POST /api/customergroup body { name } → 201 { customergroup: { id, name, sort } } */
create: (body) => this.#json('POST', '/api/customergroup', { body }),
/** PATCH /api/customergroup/{id} → { customergroup } */
/** PATCH /api/customergroup/{id} body { name } → { customergroup: { id, name, sort } } */
update: (id, body) =>
this.#json('PATCH', `/api/customergroup/${enc(id)}`, { body }),
/** PUT /api/customergroup/order body { customergroupIds } → { customergroupIds } */
order: (body) => this.#json('PUT', '/api/customergroup/order', { body }),
/** DELETE /api/customergroup/{id} → 204 */
delete: (id) => this.#empty('DELETE', `/api/customergroup/${enc(id)}`),
};

View File

@@ -682,17 +682,20 @@ export const order = {
/**
* Company-scoped customer groups.
* Shape: CustomerGroup = { id, name }
* Shape: CustomerGroup = { id, name, sort }
* List item: CustomerGroup & { editable } — editable false for POS / Lieferanten
* (name locked). Reorder via PUT /api/customergroup/order.
*/
export const customergroup = {
/** GET /api/customergroup → { customergroups: CustomerGroup[] } */
/** GET /api/customergroup → { customergroups: (CustomerGroup & { editable })[] } ordered by sort */
list() {
return http('/api/customergroup');
},
/**
* POST /api/customergroup
* Body: { name } — empty name ⇒ 400 Name required.
* Body: { name } — empty name ⇒ 400 Name required;
* reserved POS / Lieferanten ⇒ 400 Name not allowed; sort appends next index.
* → 201 { customergroup: CustomerGroup }
*/
create(body) {
@@ -701,13 +704,23 @@ export const customergroup = {
/**
* PATCH /api/customergroup/:id
* Body: { name }
* Body: { name } — locked groups cannot be renamed (Name cannot be changed).
* → 200 { customergroup: CustomerGroup }
*/
update(id, body) {
return http(`/api/customergroup/${id}`, { method: 'PATCH', body });
},
/**
* PUT /api/customergroup/order
* Body: { customergroupIds: number[] } — must be exactly the company set (same ids, no dups)
* else 400 Invalid customer group order. Sets sort to each id’s index 0…n-1.
* → 200 { customergroupIds: number[] }
*/
order(body) {
return http('/api/customergroup/order', { method: 'PUT', body });
},
/** DELETE /api/customergroup/:id → 204 · 409 Customer group in use */
delete(id) {
return http(`/api/customergroup/${id}`, { method: 'DELETE' });