From 5d2c8fdfed7abee8b8536a41d8fe3dbeea248269 Mon Sep 17 00:00:00 2001 From: seb Date: Mon, 28 Sep 2026 06:50:10 +0200 Subject: [PATCH] u --- API.labeltemplate.md | 20 +++++++++----------- API.md | 6 ++++++ src/store/labeltemplate/list.js | 13 ++++++++++++- 3 files changed, 27 insertions(+), 12 deletions(-) diff --git a/API.labeltemplate.md b/API.labeltemplate.md index 76aaa47..377a8b5 100644 --- a/API.labeltemplate.md +++ b/API.labeltemplate.md @@ -18,9 +18,9 @@ Creates a new label template for the user's selected company. | `input.width` | `number` | Canvas width in pixels. | | `input.height` | `number` | Canvas height in pixels. | | `input.dpi` | `number` | Printer DPI (203 or 300). | -| `input.type` | `string` | Template type (`"zpl"`). | -| `input.content` | `object` | Template content (JSON — label editor objects). | -| `[input.thumb]` | `Buffer\|null` | Optional pre-rendered 50×50 1-bit PNG thumbnail. | +| `input.type` | `string` | Template type ("zpl"). | +| `input.content` | `object` | Template content (JSON). | +| `[input.thumb]` | `Buffer|null` | 50×50 1-bit PNG thumbnail buffer. | | `[tx]` | `object` | Optional transaction to run within. | **Returns** @@ -29,7 +29,7 @@ Creates a new label template for the user's selected company. **Throws** -`Error` — If name, content or dimensions are missing, or dpi/type is invalid. +`Error` — If required fields are missing or invalid. **Example** @@ -88,14 +88,13 @@ Retrieves a label template by its ID for the user's selected company. ```js const template = await store.labeltemplate.getById(googleAuthId, 1); -// => { id: 1, company_id: 1, name: 'Product Label', width: 448, height: 200, dpi: 203, type: 'zpl', ... } ``` ## `labeltemplate.list` *Source: `src/store/labeltemplate/list.js`* -Lists all label templates for the user's selected company. +Lists all label templates for the user's selected company. `content.objects` is omitted to reduce payload size. **Parameters** @@ -112,7 +111,6 @@ Lists all label templates for the user's selected company. ```js const templates = await store.labeltemplate.list(42); -// => [{ id: 1, company_id: 1, name: 'Product Label', ... }] ``` ## `labeltemplate.update` @@ -127,14 +125,14 @@ Updates a label template for the user's selected company. | --- | --- | --- | | `googleAuthId` | `number` | The id of the Google auth user. | | `id` | `number` | The label template ID to update. | -| `input` | `object` | Update payload (all fields optional). | +| `input` | `object` | Update payload. | | `[input.name]` | `string` | Template name. | | `[input.width]` | `number` | Canvas width in pixels. | | `[input.height]` | `number` | Canvas height in pixels. | | `[input.dpi]` | `number` | Printer DPI (203 or 300). | -| `[input.type]` | `string` | Template type (`"zpl"`). | +| `[input.type]` | `string` | Template type ("zpl"). | | `[input.content]` | `object` | Template content (JSON). | -| `[input.thumb]` | `Buffer\|null` | 50×50 1-bit PNG thumbnail. | +| `[input.thumb]` | `Buffer|null` | 50×50 1-bit PNG thumbnail buffer. | | `[tx]` | `object` | Optional transaction to run within. | **Returns** @@ -143,4 +141,4 @@ Updates a label template for the user's selected company. **Throws** -`Error` — If template not found, name is empty, or dpi/type is invalid. +`Error` — If template not found or input invalid. diff --git a/API.md b/API.md index 01e3295..490786b 100644 --- a/API.md +++ b/API.md @@ -215,5 +215,11 @@ The store is exposed as a `LibDashStore` instance (see `src/index.js`). Each met - [numbers](API.numbers.md) - `list(googleAuthId: number, tx?: object): Promise>` - `update(googleAuthId: number, id: number, input: {prefix?: string, padding?: number, next?: number}, tx?: object): Promise<{id: number, type: string, prefix: string, padding: number, next: number}>` +- [labeltemplate](API.labeltemplate.md) + - `create(googleAuthId: number, input: {name: string, width: number, height: number, dpi: number, type: string, content: object, thumb?: Buffer|null}, tx?: object): Promise<{id: number, company_id: number, name: string, width: number, height: number, dpi: number, type: string, content: object, thumb: Buffer|null}>` + - `delete(googleAuthId: number, id: number, tx?: object): Promise` + - `getById(googleAuthId: number, id: number, tx?: object): Promise<{id: number, company_id: number, name: string, width: number, height: number, dpi: number, type: string, content: object, thumb: Buffer|null}|undefined>` + - `list(googleAuthId: number, tx?: object): Promise>` + - `update(googleAuthId: number, id: number, input: {name?: string, width?: number, height?: number, dpi?: number, type?: string, content?: object, thumb?: Buffer|null}, tx?: object): Promise<{id: number, company_id: number, name: string, width: number, height: number, dpi: number, type: string, content: object, thumb: Buffer|null}>` - [runner.js](API.runner.js.md) - `runner(provider: import('../providers/provider.js').DatabaseProvider, tx?: object): ((sql: string, params?: object) => Promise) & { query: Function, dialect?: string }` diff --git a/src/store/labeltemplate/list.js b/src/store/labeltemplate/list.js index 0173a11..ecccfdf 100644 --- a/src/store/labeltemplate/list.js +++ b/src/store/labeltemplate/list.js @@ -4,6 +4,16 @@ import resolveSelectedCompanyAccess from '../companyuser/resolveSelectedCompanyA import makeRunner from '../runner.js'; function shape(row) { + let content = typeof row.content === 'string' ? JSON.parse(row.content) : row.content; + if (content && typeof content === 'object') { + if (Array.isArray(content)) { + content = []; + } else { + const { objects: _objects, ...rest } = content; + content = rest; + } + } + return { id: row.id, company_id: row.company_id ?? row.companyId, @@ -12,7 +22,7 @@ function shape(row) { height: row.height, dpi: row.dpi, type: row.type, - content: typeof row.content === 'string' ? JSON.parse(row.content) : row.content, + content, thumb: row.thumb ?? null, }; } @@ -26,6 +36,7 @@ export default function list(provider) { /** * Lists all label templates for the user's selected company. + * `content.objects` is omitted to reduce payload size. * * @param {number} googleAuthId - The id of the Google auth user. * @param {object} [tx] - Optional transaction to run within.