u
This commit is contained in:
@@ -18,9 +18,9 @@ Creates a new label template for the user's selected company.
|
|||||||
| `input.width` | `number` | Canvas width in pixels. |
|
| `input.width` | `number` | Canvas width in pixels. |
|
||||||
| `input.height` | `number` | Canvas height in pixels. |
|
| `input.height` | `number` | Canvas height in pixels. |
|
||||||
| `input.dpi` | `number` | Printer DPI (203 or 300). |
|
| `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 — label editor objects). |
|
| `input.content` | `object` | Template content (JSON). |
|
||||||
| `[input.thumb]` | `Buffer\|null` | Optional pre-rendered 50×50 1-bit PNG thumbnail. |
|
| `[input.thumb]` | `Buffer|null` | 50×50 1-bit PNG thumbnail buffer. |
|
||||||
| `[tx]` | `object` | Optional transaction to run within. |
|
| `[tx]` | `object` | Optional transaction to run within. |
|
||||||
|
|
||||||
**Returns**
|
**Returns**
|
||||||
@@ -29,7 +29,7 @@ Creates a new label template for the user's selected company.
|
|||||||
|
|
||||||
**Throws**
|
**Throws**
|
||||||
|
|
||||||
`Error` — If name, content or dimensions are missing, or dpi/type is invalid.
|
`Error` — If required fields are missing or invalid.
|
||||||
|
|
||||||
**Example**
|
**Example**
|
||||||
|
|
||||||
@@ -88,14 +88,13 @@ Retrieves a label template by its ID for the user's selected company.
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
const template = await store.labeltemplate.getById(googleAuthId, 1);
|
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`
|
## `labeltemplate.list`
|
||||||
|
|
||||||
*Source: `src/store/labeltemplate/list.js`*
|
*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**
|
**Parameters**
|
||||||
|
|
||||||
@@ -112,7 +111,6 @@ Lists all label templates for the user's selected company.
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
const templates = await store.labeltemplate.list(42);
|
const templates = await store.labeltemplate.list(42);
|
||||||
// => [{ id: 1, company_id: 1, name: 'Product Label', ... }]
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## `labeltemplate.update`
|
## `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. |
|
| `googleAuthId` | `number` | The id of the Google auth user. |
|
||||||
| `id` | `number` | The label template ID to update. |
|
| `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.name]` | `string` | Template name. |
|
||||||
| `[input.width]` | `number` | Canvas width in pixels. |
|
| `[input.width]` | `number` | Canvas width in pixels. |
|
||||||
| `[input.height]` | `number` | Canvas height in pixels. |
|
| `[input.height]` | `number` | Canvas height in pixels. |
|
||||||
| `[input.dpi]` | `number` | Printer DPI (203 or 300). |
|
| `[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.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. |
|
| `[tx]` | `object` | Optional transaction to run within. |
|
||||||
|
|
||||||
**Returns**
|
**Returns**
|
||||||
@@ -143,4 +141,4 @@ Updates a label template for the user's selected company.
|
|||||||
|
|
||||||
**Throws**
|
**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
6
API.md
@@ -215,5 +215,11 @@ The store is exposed as a `LibDashStore` instance (see `src/index.js`). Each met
|
|||||||
- [numbers](API.numbers.md)
|
- [numbers](API.numbers.md)
|
||||||
- `list(googleAuthId: number, tx?: object): Promise<Array<{id: number, type: string, prefix: string, padding: number, next: number}>>`
|
- `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}>`
|
- `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.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 }`
|
- `runner(provider: import('../providers/provider.js').DatabaseProvider, tx?: object): ((sql: string, params?: object) => Promise<import('../providers/provider.js').QueryResult>) & { query: Function, dialect?: string }`
|
||||||
|
|||||||
@@ -4,6 +4,16 @@ import resolveSelectedCompanyAccess from '../companyuser/resolveSelectedCompanyA
|
|||||||
import makeRunner from '../runner.js';
|
import makeRunner from '../runner.js';
|
||||||
|
|
||||||
function shape(row) {
|
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 {
|
return {
|
||||||
id: row.id,
|
id: row.id,
|
||||||
company_id: row.company_id ?? row.companyId,
|
company_id: row.company_id ?? row.companyId,
|
||||||
@@ -12,7 +22,7 @@ function shape(row) {
|
|||||||
height: row.height,
|
height: row.height,
|
||||||
dpi: row.dpi,
|
dpi: row.dpi,
|
||||||
type: row.type,
|
type: row.type,
|
||||||
content: typeof row.content === 'string' ? JSON.parse(row.content) : row.content,
|
content,
|
||||||
thumb: row.thumb ?? null,
|
thumb: row.thumb ?? null,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -26,6 +36,7 @@ export default function list(provider) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 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.
|
||||||
*
|
*
|
||||||
* @param {number} googleAuthId - The id of the Google auth user.
|
* @param {number} googleAuthId - The id of the Google auth user.
|
||||||
* @param {object} [tx] - Optional transaction to run within.
|
* @param {object} [tx] - Optional transaction to run within.
|
||||||
|
|||||||
Reference in New Issue
Block a user