This commit is contained in:
seb
2026-09-27 21:01:30 +02:00
parent f9c570a036
commit 0cafa11a32
34 changed files with 2010 additions and 1534 deletions

View File

@@ -15,21 +15,22 @@ Creates a new warehouse for the user's selected company.
| `googleAuthId` | `number` | The id of the Google auth user. |
| `input` | `object` | Warehouse input. |
| `input.name` | `string` | The warehouse name. |
| `[input.sort]` | `number` | Optional sort order (auto-increments if omitted). |
| `[tx]` | `object` | Optional transaction to run within. |
**Returns**
`Promise<{id: number, name: string}>` — The created warehouse.
`Promise<{id: number, name: string, sort: number}>` — The created warehouse.
**Throws**
`Error` — If name is missing or already exists.
`Error` — If name is missing, sort is invalid, or name already exists.
**Example**
```js
const wh = await store.warehouse.create(googleAuthId, { name: 'Hauptlager' });
// => { id: 1, name: 'Hauptlager' }
// => { id: 1, name: 'Hauptlager', sort: 0 }
```
## `warehouse.delete`
@@ -76,13 +77,13 @@ Retrieves a warehouse by its ID for the user's selected company.
**Returns**
`Promise<{id: number, name: string}|undefined>` — The warehouse or undefined.
`Promise<{id: number, name: string, sort: number}|undefined>` — The warehouse or undefined.
**Example**
```js
const wh = await store.warehouse.getById(googleAuthId, 1);
// => { id: 1, name: 'Hauptlager' }
// => { id: 1, name: 'Hauptlager', sort: 0 }
```
## `warehouse.list`
@@ -100,20 +101,43 @@ Lists all warehouses for the user's selected company.
**Returns**
`Promise<Array<{id: number, name: string}>>` — List of warehouses.
`Promise<Array<{id: number, name: string, sort: number}>>` — List of warehouses.
**Example**
```js
const warehouses = await store.warehouse.list(googleAuthId);
// => [{ id: 1, name: 'Hauptlager' }]
// => [{ id: 1, name: 'Hauptlager', sort: 0 }]
```
## `warehouse.order`
*Source: `src/store/warehouse/order.js`*
Reorders the warehouses of the user's selected company.
**Parameters**
| Name | Type | Description |
| --- | --- | --- |
| `googleAuthId` | `number` | The id of the Google auth user. |
| `input` | `object` | The reorder input. |
| `input.warehouseIds` | `Array<number>` | The warehouse ids in their new order. |
| `[tx]` | `object` | Optional transaction to run within. |
**Returns**
`Promise<{warehouseIds: Array<number>}>` — The applied order.
**Throws**
`Error` — If the order is invalid.
## `warehouse.update`
*Source: `src/store/warehouse/update.js`*
Updates a warehouse name for the user's selected company.
Updates a warehouse name and/or sort order for the user's selected company.
**Parameters**
@@ -122,20 +146,21 @@ Updates a warehouse name for the user's selected company.
| `googleAuthId` | `number` | The id of the Google auth user. |
| `id` | `number` | The warehouse ID to update. |
| `input` | `object` | Update payload. |
| `input.name` | `string` | The new warehouse name. |
| `[input.name]` | `string` | The new warehouse name. |
| `[input.sort]` | `number` | The new sort order. |
| `[tx]` | `object` | Optional transaction to run within. |
**Returns**
`Promise<{id: number, name: string}>` — The updated warehouse.
`Promise<{id: number, name: string, sort: number}>` — The updated warehouse.
**Throws**
`Error` — If warehouse not found, name is missing, or name already exists.
`Error` — If warehouse not found, name is empty, sort is invalid, or name already exists.
**Example**
```js
const updated = await store.warehouse.update(googleAuthId, 1, { name: 'Zentrallager' });
// => { id: 1, name: 'Zentrallager' }
const updated = await store.warehouse.update(googleAuthId, 1, { name: 'Zentrallager', sort: 1 });
// => { id: 1, name: 'Zentrallager', sort: 1 }
```