This commit is contained in:
seb
2026-09-28 06:50:10 +02:00
parent 87da854de4
commit 5d2c8fdfed
3 changed files with 27 additions and 12 deletions

View File

@@ -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.

6
API.md
View File

@@ -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<Array<{id: number, type: string, prefix: string, padding: number, next: number}>>`
- `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<void>`
- `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<Array<{id: number, company_id: number, name: string, width: number, height: number, dpi: number, type: string, content: object, thumb: Buffer|null}>>`
- `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<import('../providers/provider.js').QueryResult>) & { query: Function, dialect?: string }`

View File

@@ -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.