feat(articlesupplier): implement store methods, schema constraints, and embed in getBySku

This commit is contained in:
seb
2026-09-17 11:41:13 +02:00
parent 1fafeeb5f2
commit 4c196c7209
15 changed files with 812 additions and 6 deletions

140
API.articlesupplier.md Normal file
View File

@@ -0,0 +1,140 @@
# articlesupplier
This document is auto-generated from the JSDoc comments in `src/store` by running `npm run api-doc`.
## `articlesupplier.create`
*Source: `src/store/articlesupplier/create.js`*
Assigns a supplier to an article, optionally creating a purchase price.
**Parameters**
| Name | Type | Description |
| --- | --- | --- |
| `googleAuthId` | `number` | The id of the Google auth user. |
| `sku` | `string` | The article SKU. |
| `input` | `object` | The supplier assignment input. |
| `input.entityId` | `number` | The id of the supplier entity. |
| `[input.sku]` | `string` | The supplier's item number/SKU. |
| `[input.pu]` | `number` | Packaging unit (defaults to 1). |
| `[input.stock]` | `number|null` | Current stock at the supplier. |
| `[input.netPrice]` | `number|null` | Net purchase price. |
| `[input.taxId]` | `number` | The tax id for the purchase price. |
| `[input.taxRate]` | `number` | The tax rate in percent (used if taxId is not provided). |
**Returns**
`Promise<{id: number, articleId: number, entityId: number, supplierName: string|null, sku: string|null, pu: number, stock: number|null, priceId: number|null, price: {net: number, taxId: number, taxRate?: number}|null}>` — The created assignment.
**Throws**
`Error` — If input is invalid, article or supplier is not found, or supplier is already assigned.
**Example**
```js
const created = await store.articlesupplier.create(42, 'SKU-1', {
entityId: 88,
sku: 'MET-44910',
pu: 1,
netPrice: 4.20,
});
// => { id, articleId, entityId, supplierName, sku, pu, stock, priceId, price }
```
## `articlesupplier.delete`
*Source: `src/store/articlesupplier/delete.js`*
Deletes a supplier assignment and cleans up its associated purchase price.
**Parameters**
| Name | Type | Description |
| --- | --- | --- |
| `googleAuthId` | `number` | The id of the Google auth user. |
| `sku` | `string` | The article SKU. |
| `id` | `number` | The id of the articlesupplier record. |
**Returns**
`Promise<void>`
**Throws**
`Error` — If the supplier assignment is not found.
**Example**
```js
await store.articlesupplier.delete(42, 'SKU-1', 12);
```
## `articlesupplier.listByArticleSku`
*Source: `src/store/articlesupplier/listByArticleSku.js`*
Lists the supplier assignments for an article by its SKU.
**Parameters**
| Name | Type | Description |
| --- | --- | --- |
| `googleAuthId` | `number` | The id of the Google auth user. |
| `sku` | `string` | The article SKU. |
**Returns**
`Promise<Array<{id: number, articleId: number, entityId: number, supplierName: string|null, sku: string|null, pu: number, stock: number|null, priceId: number|null, price: {net: number, taxId: number, taxRate?: number}|null}>>` — The supplier assignments.
**Throws**
`Error` — If the article is not found or the user is not authorized.
**Example**
```js
const suppliers = await store.articlesupplier.listByArticleSku(42, 'SKU-1');
// => [{ id, articleId, entityId, supplierName, sku, pu, stock, priceId, price }]
```
## `articlesupplier.update`
*Source: `src/store/articlesupplier/update.js`*
Updates an existing supplier assignment and its associated purchase price.
**Parameters**
| Name | Type | Description |
| --- | --- | --- |
| `googleAuthId` | `number` | The id of the Google auth user. |
| `sku` | `string` | The article SKU. |
| `id` | `number` | The id of the articlesupplier record. |
| `patch` | `object` | The fields to update. |
| `[patch.sku]` | `string|null` | The supplier's item number/SKU. |
| `[patch.pu]` | `number` | Packaging unit (> 0). |
| `[patch.stock]` | `number|null` | Current stock at the supplier. |
| `[patch.netPrice]` | `number|null` | Net purchase price. |
| `[patch.taxId]` | `number` | The tax id for the purchase price. |
| `[patch.taxRate]` | `number` | The tax rate in percent. |
**Returns**
`Promise<{id: number, articleId: number, entityId: number, supplierName: string|null, sku: string|null, pu: number, stock: number|null, priceId: number|null, price: {net: number, taxId: number, taxRate?: number}|null}>` — The updated assignment.
**Throws**
`Error` — If input is invalid or supplier assignment is not found.
**Example**
```js
const updated = await store.articlesupplier.update(42, 'SKU-1', 12, {
sku: 'MET-44910-B',
pu: 6,
netPrice: 22.50,
});
// => { id, articleId, entityId, supplierName, sku, pu, stock, priceId, price }
```