From 61529023b0d76d91582ff2cbc933dc67cb5db94d Mon Sep 17 00:00:00 2001 From: seb Date: Fri, 30 Oct 2026 16:56:27 +0100 Subject: [PATCH] u --- docs/api/routes-all.md | 34 ++++++++--------- docs/api/routes.md | 34 ++++++++--------- docs/api/routes/printeragent.get.md | 3 +- docs/api/routes/printeragent.put.md | 4 +- docs/api/routes/printeragent/_id.patch.md | 13 +++++-- src/api/openapi.js | 4 ++ src/api/routes/printeragent.js | 45 ++++++++++++++++++++--- 7 files changed, 91 insertions(+), 46 deletions(-) diff --git a/docs/api/routes-all.md b/docs/api/routes-all.md index 2f2a364..2d312fd 100644 --- a/docs/api/routes-all.md +++ b/docs/api/routes-all.md @@ -16,9 +16,9 @@ Params: path values first, then `query:` and `body:` (`body?` = optional body). - `T5` = `{ name: str, path: str, totalSizeBytes: int, timestamp: str|null, manifest?: T6|null }` - `T6` = `{ id: str, timestamp: str, dateKey: str, monthKey: str, dbProvider: str, files: T12, totalSizeBytes: int, durationMs: int }` - `T7` = `{ id: int, name: str, pairingpin?: str|null, token?: str|null, pairedAt?: str|null, clientserial?: str|null, rootCategoryId?: int|null, syncRootArticles?: bool, sort?: int, enabled?: bool, clientversion?: str|null, lastseenAt?: str|null, updatedAt?: str|null, categoryIds?: int[] }` -- `T8` = `{ id: int, articleId: int, entityId: int, pu: num, sort: int, supplierName?: str|null, sku?: str|null, stock?: num|null, priceId?: int|null, price?: T39|null, incoming?: { date: str, amount: num }[] }` -- `T9` = `{ id: int, name: str, width: num, height: num, dpi: int, type: str, content: { objects: T23[] }, thumb?: str|null }` -- `T10` = `{ id: int, name: str, companyId?: int, token?: str|null, pairingpin?: str|null, pairedAt?: str|null, clientserial?: str|null, clientmodel?: str|null, clientstate?: str|null, agentversion?: str|null, lastseenAt?: str|null, updatedAt?: str }` +- `T8` = `{ id: int, name: str, companyId?: int, token?: str|null, pairingpin?: str|null, pairedAt?: str|null, clientserial?: str|null, clientmodel?: str|null, clientstate?: str|null, agentversion?: str|null, lastseenAt?: str|null, updatedAt?: str, sort?: int }` +- `T9` = `{ id: int, articleId: int, entityId: int, pu: num, sort: int, supplierName?: str|null, sku?: str|null, stock?: num|null, priceId?: int|null, price?: T39|null, incoming?: { date: str, amount: num }[] }` +- `T10` = `{ id: int, name: str, width: num, height: num, dpi: int, type: str, content: { objects: T23[] }, thumb?: str|null }` - `T11` = `{ id: int, manifestId: int, fileId: int, sort: int, hash: str, mimetype: str, name: str, size: int, created?: str, modified?: str, skeledash?: str|null, thumbx?: int|null, thumby?: int|null, meta?: { [k]: str }|null }` - `T12` = `{ vfs: T38, storage: T38, database: T32 }` - `T13` = `{ id: int, entityId: int, addressType: str, firstName?: str|null, name?: str|null, street?: str|null, streetNumber?: str|null, zip?: str|null, city?: str|null, county?: str|null }` @@ -89,7 +89,7 @@ _none_ - Returns: `204 void` #### Get article by SKU — `GET /article/{sku}` - Params: `sku: str` -- Returns: `200 { article: { id: int, sku: str, name: str, slug: str, desc: str|null, seo: str|null, track_stock: bool, unitamount: num|null, weight: num|null, unit: T27, brand: T26|null, categoryIds: int[], photos: { sort: int, fullHash: str, fullW: int, fullH: int, fullSize: int, thumbW: int, thumbH: int, thumbHash: str }[], eans: str[], prices: { minmultiplier: num, net: num, taxRate: num, customergroupId: int }[], suppliers: T8[], undeliveredOrders: { orderId: int, orderNumber: str, date: str, amount: num, customerName?: str|null }[] } }` +- Returns: `200 { article: { id: int, sku: str, name: str, slug: str, desc: str|null, seo: str|null, track_stock: bool, unitamount: num|null, weight: num|null, unit: T27, brand: T26|null, categoryIds: int[], photos: { sort: int, fullHash: str, fullW: int, fullH: int, fullSize: int, thumbW: int, thumbH: int, thumbHash: str }[], eans: str[], prices: { minmultiplier: num, net: num, taxRate: num, customergroupId: int }[], suppliers: T9[], undeliveredOrders: { orderId: int, orderNumber: str, date: str, amount: num, customerName?: str|null }[] } }` #### Update article by SKU — `PATCH /article/{sku}` - Params: `sku: str, body: { name?: str, desc?: str, seo?: str, unitamount?: num, unitSi?: str, track_stock?: bool }` - Returns: `204 void` @@ -164,10 +164,10 @@ _none_ - Returns: `200 { ok: bool }` #### List article suppliers — `GET /article/{sku}/supplier` - Params: `sku: str` -- Returns: `200 { suppliers: T8[] }` +- Returns: `200 { suppliers: T9[] }` #### Assign supplier to article — `POST /article/{sku}/supplier` - Params: `sku: str, body: { entityId: int, sku?: str|null, pu?: num, stock?: num|null, sort?: int|null, netPrice?: num|null, taxId?: int|null, taxRate?: num|null }` -- Returns: `201 { supplier: T8 }` +- Returns: `201 { supplier: T9 }` #### Reorder article suppliers — `PUT /article/{sku}/supplier/order` - Params: `sku: str, body: { ids: int[] }` - Returns: `200 { ids: int[] }` @@ -176,7 +176,7 @@ _none_ - Returns: `204 void` #### Update article supplier assignment — `PATCH /article/{sku}/supplier/{id}` - Params: `sku: str, id: int, body: { sku?: str|null, pu?: num, stock?: num|null, sort?: int, netPrice?: num|null, taxId?: int|null, taxRate?: num|null }` -- Returns: `200 { supplier: T8 }` +- Returns: `200 { supplier: T9 }` #### Set article track_stock flag by SKU — `PUT /article/{sku}/track_stock` - Params: `sku: str, body: { track_stock: bool }` - Returns: `204 void` @@ -519,19 +519,19 @@ _none_ - Returns: `200 { labeltemplates: { id: int, name: str, width: num, height: num, dpi: int, type: str, thumb?: str|null }[] }` #### Create label template — `POST /labeltemplate` - Params: `body: { name: str, width: num, height: num, dpi: int, type: str, content: { objects: T23[] } }` -- Returns: `201 { labeltemplate: T9 }` +- Returns: `201 { labeltemplate: T10 }` #### Delete label template — `DELETE /labeltemplate/{id}` - Params: `id: int` - Returns: `204 void` #### Get label template by ID — `GET /labeltemplate/{id}` - Params: `id: int` -- Returns: `200 { labeltemplate: T9 }` +- Returns: `200 { labeltemplate: T10 }` #### Update label template (partial) — `PATCH /labeltemplate/{id}` - Params: `id: int, body: { name?: str, width?: num, height?: num, dpi?: int, type?: str, content?: { objects: T23[] } }` -- Returns: `200 { labeltemplate: T9 }` +- Returns: `200 { labeltemplate: T10 }` #### Update label template — `PUT /labeltemplate/{id}` - Params: `id: int, body: { name?: str, width?: num, height?: num, dpi?: int, type?: str, content?: { objects: T23[] } }` -- Returns: `200 { labeltemplate: T9 }` +- Returns: `200 { labeltemplate: T10 }` ### Section: /ledger @@ -732,16 +732,16 @@ _none_ #### List printer agents — `GET /printeragent` _none_ -- Returns: `200 { printeragents: T10[] }` +- Returns: `200 { printeragents: T8[] }` #### Create printer agent — `PUT /printeragent` -- Params: `body: { name: str }` -- Returns: `200 { printeragent: T10 }` +- Params: `body: { name: str, sort?: int }` +- Returns: `200 { printeragent: T8 }` #### Delete printer agent — `DELETE /printeragent/{id}` - Params: `id: int` - Returns: `204 void` -#### Rename printer agent — `PATCH /printeragent/{id}` -- Params: `id: int, body: { name: str }` -- Returns: `200 { printeragent: T10 }` +#### Update printer agent — `PATCH /printeragent/{id}` +- Params: `id: int, body: { name?: str, sort?: int }` +- Returns: `200 { printeragent: T8 }` ### Section: /propertyname diff --git a/docs/api/routes.md b/docs/api/routes.md index a30f36e..e3aa1a5 100644 --- a/docs/api/routes.md +++ b/docs/api/routes.md @@ -13,9 +13,9 @@ Params: path values first, then `query:` and `body:` (`body?` = optional body). - `T2` = `{ id: int, number: str, type: str, date: str, lines: T13[], shippings: T15[], entityId?: int|null, externalNumber?: str|null, createdAt?: str|null, lineCount?: int, packageCount?: int, files?: T8[], state?: str }` - `T3` = `{ id: int, number: str, type: str, date: str, lines: T13[], entityId?: int|null, externalNumber?: str|null, createdAt?: str, positions?: int, grossTotal?: num, totalQuantity?: num, customerName?: str|null, files?: T8[] }` - `T4` = `{ id: int, number: str, type: str, supplierId: int, date: str, lines: T16[], files: T8[], externalNumber?: str|null, createdAt?: str, ledger?: T28 }` -- `T5` = `{ id: int, articleId: int, entityId: int, pu: num, sort: int, supplierName?: str|null, sku?: str|null, stock?: num|null, priceId?: int|null, price?: T29|null, incoming?: { date: str, amount: num }[] }` -- `T6` = `{ id: int, name: str, width: num, height: num, dpi: int, type: str, content: { objects: T17[] }, thumb?: str|null }` -- `T7` = `{ id: int, name: str, companyId?: int, token?: str|null, pairingpin?: str|null, pairedAt?: str|null, clientserial?: str|null, clientmodel?: str|null, clientstate?: str|null, agentversion?: str|null, lastseenAt?: str|null, updatedAt?: str }` +- `T5` = `{ id: int, name: str, companyId?: int, token?: str|null, pairingpin?: str|null, pairedAt?: str|null, clientserial?: str|null, clientmodel?: str|null, clientstate?: str|null, agentversion?: str|null, lastseenAt?: str|null, updatedAt?: str, sort?: int }` +- `T6` = `{ id: int, articleId: int, entityId: int, pu: num, sort: int, supplierName?: str|null, sku?: str|null, stock?: num|null, priceId?: int|null, price?: T29|null, incoming?: { date: str, amount: num }[] }` +- `T7` = `{ id: int, name: str, width: num, height: num, dpi: int, type: str, content: { objects: T17[] }, thumb?: str|null }` - `T8` = `{ id: int, manifestId: int, fileId: int, sort: int, hash: str, mimetype: str, name: str, size: int, created?: str, modified?: str, skeledash?: str|null, thumbx?: int|null, thumby?: int|null, meta?: { [k]: str }|null }` - `T9` = `{ id: int, entityId: int, addressType: str, firstName?: str|null, name?: str|null, street?: str|null, streetNumber?: str|null, zip?: str|null, city?: str|null, county?: str|null }` - `T10` = `{ id: int, company_id: int, prompt: str, max_itr: int, cron: str, created_at: str, desc?: str|null, skills?: str|null, lastagentnote?: str|null, lastrun_at?: str|null }` @@ -55,7 +55,7 @@ Params: path values first, then `query:` and `body:` (`body?` = optional body). - Returns: `204 void` #### Get article by SKU — `GET /article/{sku}` - Params: `sku: str` -- Returns: `200 { article: { id: int, sku: str, name: str, slug: str, desc: str|null, seo: str|null, track_stock: bool, unitamount: num|null, weight: num|null, unit: T20, brand: { name: str, id?: int|null, fullHash?: str|null, thumbW?: int|null, thumbH?: int|null, thumbHash?: str|null }, categoryIds: int[], photos: { sort: int, fullHash: str, fullW: int, fullH: int, fullSize: int, thumbW: int, thumbH: int, thumbHash: str }[], eans: str[], prices: { minmultiplier: num, net: num, taxRate: num, customergroupId: int }[], suppliers: T5[], undeliveredOrders: { orderId: int, orderNumber: str, date: str, amount: num, customerName?: str|null }[] } }` +- Returns: `200 { article: { id: int, sku: str, name: str, slug: str, desc: str|null, seo: str|null, track_stock: bool, unitamount: num|null, weight: num|null, unit: T20, brand: { name: str, id?: int|null, fullHash?: str|null, thumbW?: int|null, thumbH?: int|null, thumbHash?: str|null }, categoryIds: int[], photos: { sort: int, fullHash: str, fullW: int, fullH: int, fullSize: int, thumbW: int, thumbH: int, thumbHash: str }[], eans: str[], prices: { minmultiplier: num, net: num, taxRate: num, customergroupId: int }[], suppliers: T6[], undeliveredOrders: { orderId: int, orderNumber: str, date: str, amount: num, customerName?: str|null }[] } }` #### Update article by SKU — `PATCH /article/{sku}` - Params: `sku: str, body: { name?: str, desc?: str, seo?: str, unitamount?: num, unitSi?: str, track_stock?: bool }` - Returns: `204 void` @@ -127,10 +127,10 @@ Params: path values first, then `query:` and `body:` (`body?` = optional body). - Returns: `200 { ok: bool }` #### List article suppliers — `GET /article/{sku}/supplier` - Params: `sku: str` -- Returns: `200 { suppliers: T5[] }` +- Returns: `200 { suppliers: T6[] }` #### Assign supplier to article — `POST /article/{sku}/supplier` - Params: `sku: str, body: { entityId: int, sku?: str|null, pu?: num, stock?: num|null, sort?: int|null, netPrice?: num|null, taxId?: int|null, taxRate?: num|null }` -- Returns: `201 { supplier: T5 }` +- Returns: `201 { supplier: T6 }` #### Reorder article suppliers — `PUT /article/{sku}/supplier/order` - Params: `sku: str, body: { ids: int[] }` - Returns: `200 { ids: int[] }` @@ -139,7 +139,7 @@ Params: path values first, then `query:` and `body:` (`body?` = optional body). - Returns: `204 void` #### Update article supplier assignment — `PATCH /article/{sku}/supplier/{id}` - Params: `sku: str, id: int, body: { sku?: str|null, pu?: num, stock?: num|null, sort?: int, netPrice?: num|null, taxId?: int|null, taxRate?: num|null }` -- Returns: `200 { supplier: T5 }` +- Returns: `200 { supplier: T6 }` #### Set article track_stock flag by SKU — `PUT /article/{sku}/track_stock` - Params: `sku: str, body: { track_stock: bool }` - Returns: `204 void` @@ -394,19 +394,19 @@ _none_ - Returns: `200 { labeltemplates: { id: int, name: str, width: num, height: num, dpi: int, type: str, thumb?: str|null }[] }` #### Create label template — `POST /labeltemplate` - Params: `body: { name: str, width: num, height: num, dpi: int, type: str, content: { objects: T17[] } }` -- Returns: `201 { labeltemplate: T6 }` +- Returns: `201 { labeltemplate: T7 }` #### Delete label template — `DELETE /labeltemplate/{id}` - Params: `id: int` - Returns: `204 void` #### Get label template by ID — `GET /labeltemplate/{id}` - Params: `id: int` -- Returns: `200 { labeltemplate: T6 }` +- Returns: `200 { labeltemplate: T7 }` #### Update label template (partial) — `PATCH /labeltemplate/{id}` - Params: `id: int, body: { name?: str, width?: num, height?: num, dpi?: int, type?: str, content?: { objects: T17[] } }` -- Returns: `200 { labeltemplate: T6 }` +- Returns: `200 { labeltemplate: T7 }` #### Update label template — `PUT /labeltemplate/{id}` - Params: `id: int, body: { name?: str, width?: num, height?: num, dpi?: int, type?: str, content?: { objects: T17[] } }` -- Returns: `200 { labeltemplate: T6 }` +- Returns: `200 { labeltemplate: T7 }` ### Section: /ledger @@ -514,16 +514,16 @@ _none_ #### List printer agents — `GET /printeragent` _none_ -- Returns: `200 { printeragents: T7[] }` +- Returns: `200 { printeragents: T5[] }` #### Create printer agent — `PUT /printeragent` -- Params: `body: { name: str }` -- Returns: `200 { printeragent: T7 }` +- Params: `body: { name: str, sort?: int }` +- Returns: `200 { printeragent: T5 }` #### Delete printer agent — `DELETE /printeragent/{id}` - Params: `id: int` - Returns: `204 void` -#### Rename printer agent — `PATCH /printeragent/{id}` -- Params: `id: int, body: { name: str }` -- Returns: `200 { printeragent: T7 }` +#### Update printer agent — `PATCH /printeragent/{id}` +- Params: `id: int, body: { name?: str, sort?: int }` +- Returns: `200 { printeragent: T5 }` ### Section: /propertyname diff --git a/docs/api/routes/printeragent.get.md b/docs/api/routes/printeragent.get.md index c3fb94a..b0442d8 100644 --- a/docs/api/routes/printeragent.get.md +++ b/docs/api/routes/printeragent.get.md @@ -25,7 +25,8 @@ Printer agent list "clientstate": "…", "agentversion": "…", "lastseenAt": "…", - "updatedAt": "…" + "updatedAt": "…", + "sort": 1 } ] } diff --git a/docs/api/routes/printeragent.put.md b/docs/api/routes/printeragent.put.md index a379a40..c0ac604 100644 --- a/docs/api/routes/printeragent.put.md +++ b/docs/api/routes/printeragent.put.md @@ -13,6 +13,7 @@ The pairingpin is randomly generated server-side and returned in the response. | Field | Required | Type | Description | |-------|----------|------|-------------| | `name` | yes | string | | +| `sort` | no | integer | | ```json { @@ -38,7 +39,8 @@ Created printer agent with generated pairingpin "clientstate": "…", "agentversion": "…", "lastseenAt": "…", - "updatedAt": "…" + "updatedAt": "…", + "sort": 1 } } ``` diff --git a/docs/api/routes/printeragent/_id.patch.md b/docs/api/routes/printeragent/_id.patch.md index d7ae426..4463644 100644 --- a/docs/api/routes/printeragent/_id.patch.md +++ b/docs/api/routes/printeragent/_id.patch.md @@ -2,7 +2,9 @@ Protected. Requires a valid session cookie (`credentials: 'include'`). -Rename printer agent +Update printer agent + +Updates name and/or display order (sort) of a printer agent. ## Path parameters @@ -14,11 +16,13 @@ Rename printer agent | Field | Required | Type | Description | |-------|----------|------|-------------| -| `name` | yes | string | | +| `name` | no | string | | +| `sort` | no | integer | | ```json { - "name": "…" + "name": "…", + "sort": 1 } ``` @@ -40,7 +44,8 @@ Updated printer agent "clientstate": "…", "agentversion": "…", "lastseenAt": "…", - "updatedAt": "…" + "updatedAt": "…", + "sort": 1 } } ``` diff --git a/src/api/openapi.js b/src/api/openapi.js index 553ab8a..42b3191 100644 --- a/src/api/openapi.js +++ b/src/api/openapi.js @@ -1752,6 +1752,10 @@ * nullable: true * updatedAt: * type: string + * sort: + * type: integer + * description: Display order (ascending) + * default: 0 * LabelObject: * type: object * required: [id, type, x, y] diff --git a/src/api/routes/printeragent.js b/src/api/routes/printeragent.js index 83b636f..b424954 100644 --- a/src/api/routes/printeragent.js +++ b/src/api/routes/printeragent.js @@ -124,6 +124,9 @@ export function register(app, basePath = '') { * properties: * name: * type: string + * sort: + * type: integer + * default: 0 * example: * name: "Bar printer" * responses: @@ -174,10 +177,22 @@ export function register(app, basePath = '') { return res.status(400).json({ error: 'name is required' }); } + let sort; + if (req.body?.sort !== undefined) { + sort = Number(req.body.sort); + if (!Number.isInteger(sort)) { + return res.status(400).json({ error: 'sort must be an integer' }); + } + } + const pairingpin = String(randomInt(100000, 999999)); try { - const printeragent = await db.create(req.user.id, { name: name.trim(), pairingpin }); + const printeragent = await db.create(req.user.id, { + name: name.trim(), + pairingpin, + sort, + }); res.status(200).json({ printeragent }); } catch (error) { const status = printeragentErrorStatus(error); @@ -193,7 +208,8 @@ export function register(app, basePath = '') { * /printeragent/{id}: * patch: * tags: [Printeragent] - * summary: Rename printer agent + * summary: Update printer agent + * description: Updates name and/or display order (sort) of a printer agent. * security: * - cookieAuth: [] * parameters: @@ -208,10 +224,11 @@ export function register(app, basePath = '') { * application/json: * schema: * type: object - * required: [name] * properties: * name: * type: string + * sort: + * type: integer * responses: * 200: * description: Updated printer agent @@ -261,12 +278,28 @@ export function register(app, basePath = '') { } const { name } = req.body ?? {}; - if (typeof name !== 'string' || !name.trim()) { - return res.status(400).json({ error: 'name is required' }); + if (name === undefined && req.body?.sort === undefined) { + return res.status(400).json({ error: 'name or sort is required' }); } + if (name !== undefined && (typeof name !== 'string' || !name.trim())) { + return res.status(400).json({ error: 'name must be a non-empty string' }); + } + + let sort; + if (req.body?.sort !== undefined) { + sort = Number(req.body.sort); + if (!Number.isInteger(sort)) { + return res.status(400).json({ error: 'sort must be an integer' }); + } + } + + const payload = { id: parsed.id }; + if (name !== undefined) payload.name = name.trim(); + if (sort !== undefined) payload.sort = sort; + try { - const printeragent = await db.update(req.user.id, { id: parsed.id, name: name.trim() }); + const printeragent = await db.update(req.user.id, payload); res.status(200).json({ printeragent }); } catch (error) { const status = printeragentErrorStatus(error);