Files
dashlibstorage/API.order.md
2026-10-08 21:50:38 +02:00

160 lines
5.2 KiB
Markdown

# order
This document is auto-generated from the JSDoc comments in `src/store` by running `npm run api-doc`.
## `order.create`
*Source: `src/store/order/create.js`*
Creates a new order for the user's selected company with its lines.
**Parameters**
| Name | Type | Description |
| --- | --- | --- |
| `googleAuthId` | `number` | The id of the Google auth user. |
| `body` | `object` | The order input. |
| `body.number` | `string` | The order number. |
| `body.date` | `string` | The order date. |
| `[body.entityId]` | `number` | The id of the customer entity. |
| `[body.externalNumber]` | `string` | An external (customer) reference number. |
| `[body.lines]` | `Array<{sku?: string, name?: string, pu?: number, amount: number, net: number, rebate?: number, taxrate: number, comment?: string|null}>` | The order lines. |
| `[tx]` | `object` | Optional transaction to run within. |
**Returns**
`Promise<{id: number, number: string, type: string, entityId: number|null, externalNumber: string|null, date: string, lines: Array<{id: number, sku: string|null, name: string|null, pu: number, amount: number, net: number, rebate: number, taxrate: number, comment: string|null}>}>` — The created order.
**Throws**
`Error` — If the order is invalid.
**Example**
```js
const order = await store.order.create(42, { number: 'B-2026-001', date: '2026-09-15', entityId: 12, lines: [...] });
// => { id, number, type, entityId, externalNumber, date, lines: [...] }
```
## `order.delete`
*Source: `src/store/order/delete.js`*
Deletes an order by its id within the user's selected company.
**Parameters**
| Name | Type | Description |
| --- | --- | --- |
| `googleAuthId` | `number` | The id of the Google auth user. |
| `id` | `number` | The id of the order to delete. |
| `[tx]` | `object` | Optional transaction. |
**Returns**
`Promise<void>`
**Throws**
`Error` — If the order is not found.
**Example**
```js
await store.order.delete(42, 5);
```
## `order.getById`
*Source: `src/store/order/getById.js`*
Returns a single order by its id within the user's selected company.
**Parameters**
| Name | Type | Description |
| --- | --- | --- |
| `googleAuthId` | `number` | The id of the Google auth user. |
| `id` | `number` | The id of the order. |
| `[tx]` | `object` | Optional transaction. |
**Returns**
`Promise<{id: number, number: string, type: string, entityId: number|null, externalNumber: string|null, date: string, lines: Array<{id: number, sku: string|null, name: string|null, pu: number, amount: number, net: number, rebate: number, taxrate: number, comment: string|null}>}>` — The order with its lines.
**Throws**
`Error` — If the order is not found.
**Example**
```js
const order = await store.order.getById(42, 5);
// => { id, number, type, entityId, externalNumber, date, lines: [...] }
```
## `order.list`
*Source: `src/store/order/list.js`*
Lists the orders of the user's selected company.
**Parameters**
| Name | Type | Description |
| --- | --- | --- |
| `googleAuthId` | `number` | The id of the Google auth user. |
| `[opts]` | `object` | Optional pagination options. |
| `[opts.offset=0]` | `number` | Number of orders to skip. |
| `[opts.limit=20]` | `number` | Number of orders to return. |
| `[tx]` | `object` | Optional transaction. |
**Returns**
`Promise<{orders: Array<{id: number, number: string, type: string, entityId: number|null, externalNumber: string|null, date: string, createdAt: string|null, lines: Array<{id: number, sku: string|null, name: string|null, pu: number, amount: number, net: number, rebate: number, taxrate: number, comment: string|null}>}>, total: number, offset: number, limit: number}|Array<object>>` — The orders.
**Example**
```js
const result = await store.order.list(42, { offset: 0, limit: 20 });
// => { orders: [...], total: 100, offset: 0, limit: 20 }
const orders = await store.order.list(42);
// => [{ id, number, type, entityId, externalNumber, date, createdAt, lines: [...] }]
```
## `order.update`
*Source: `src/store/order/update.js`*
Updates an order's header and/or lines.
**Parameters**
| Name | Type | Description |
| --- | --- | --- |
| `googleAuthId` | `number` | The id of the Google auth user. |
| `id` | `number` | The id of the order to update. |
| `patch` | `object` | The update patch. |
| `[patch.number]` | `string` | The new order number. |
| `[patch.date]` | `string` | The new order date. |
| `[patch.entityId]` | `number` | The new customer entity id. |
| `[patch.externalNumber]` | `string` | The new external (customer) reference number. |
| `[patch.lines]` | `Array<{sku?: string, name?: string, pu?: number, amount: number, net: number, rebate?: number, taxrate: number, comment?: string|null}>` | The new order lines. |
| `[tx]` | `object` | Optional transaction to run within. |
**Returns**
`Promise<{id: number, number: string, type: string, entityId: number|null, externalNumber: string|null, date: string, lines: Array<{id: number, sku: string|null, name: string|null, pu: number, amount: number, net: number, rebate: number, taxrate: number, comment: string|null}>}>` — The updated order.
**Throws**
`Error` — If the order is not found.
**Example**
```js
const order = await store.order.update(42, 5, { number: 'B-2026-002', lines: [...] });
// => { id, number, type, entityId, date, lines: [...] }
```