Files
dashlibstorage/API.company.md
2026-10-19 23:56:56 +02:00

226 lines
5.8 KiB
Markdown

# company
This document is auto-generated from the JSDoc comments in `src/store` by running `npm run api-doc`.
## `company.addHistory`
*Source: `src/store/company/addHistory.js`*
Adds an entry to the company history for the user's selected company.
**Parameters**
| Name | Type | Description |
| --- | --- | --- |
| `googleAuthId` | `number` | The id of the Google auth user. |
| `input` | `object|string` | The history input object or text string. |
| `[input.text]` | `string` | The history entry text. |
| `[tx]` | `object` | Optional transaction. |
**Returns**
`Promise<{id: number, companyuserId: number|null, date: string, text: string}>` — The inserted entry.
**Throws**
`Error` — If text is missing or user is not authorized.
**Example**
```js
const entry = await store.company.addHistory(42, { text: 'API suggestion: add barcode scanner endpoint' });
// => { id, companyuserId, date, text }
```
## `company.create`
*Source: `src/store/company/create.js`*
Creates a new company together with its root category, POS customer group, default language and tax rates, and links it to the given Google auth user.
**Parameters**
| Name | Type | Description |
| --- | --- | --- |
| `input` | `object` | The company creation input. |
| `input.iso639` | `string` | The ISO 639 language code for the company. |
| `input.name` | `string` | The company name. |
| `input.taxrate` | `number` | The standard tax rate in percent. |
| `input.reducedtaxrate` | `number` | The reduced tax rate in percent. |
| `input.googleAuthId` | `number` | The id of the Google auth user to link. |
| `[tx]` | `object` | Optional transaction to run within. |
**Returns**
`Promise<{id: number, rootCategoryId: number, languageId: number, taxrateId: number, reducedtaxrateId: number, taxfreerateId: number, posCustomerGroupId: number}>` — The created company ids.
**Example**
```js
const company = await store.company.create({
iso639: 'de',
name: 'Acme',
taxrate: 19,
reducedtaxrate: 7,
googleAuthId: 42,
});
// => { id, rootCategoryId, languageId, taxrateId, reducedtaxrateId, taxfreerateId, posCustomerGroupId }
```
## `company.delete`
*Source: `src/store/company/delete.js`*
Deletes a company by its id.
**Parameters**
| Name | Type | Description |
| --- | --- | --- |
| `companyId` | `number` | The id of the company to delete. |
| `[tx]` | `object` | Optional transaction to run within. |
**Returns**
`Promise<void>`
**Example**
```js
await store.company.delete(1);
```
## `company.getById`
*Source: `src/store/company/getById.js`*
Returns a single company by its id.
**Parameters**
| Name | Type | Description |
| --- | --- | --- |
| `id` | `number` | The id of the company. |
| `[tx]` | `object` | Optional transaction to run within. |
**Returns**
`Promise<object|undefined>` — The company row, or `undefined` if not found.
**Example**
```js
const company = await store.company.getById(1);
// => { id, name, ... }
```
## `company.getByName`
*Source: `src/store/company/getByName.js`*
Returns a single company by its name.
**Parameters**
| Name | Type | Description |
| --- | --- | --- |
| `name` | `string` | The company name. |
| `[tx]` | `object` | Optional transaction to run within. |
**Returns**
`Promise<object|undefined>` — The company row, or `undefined` if not found.
**Example**
```js
const company = await store.company.getByName('Acme');
// => { id, name, ... }
```
## `company.getHistory`
*Source: `src/store/company/getHistory.js`*
Returns the company history for the user's selected company, newest first.
**Parameters**
| Name | Type | Description |
| --- | --- | --- |
| `googleAuthId` | `number` | The id of the Google auth user. |
| `[opts]` | `object` | Optional options. |
| `[opts.limit]` | `number` | Maximum number of entries to return (newest first). |
| `[tx]` | `object` | Optional transaction. |
**Returns**
`Promise<Array<{id: number, companyuserId: number|null, date: string, text: string}>>` — The company history entries.
**Example**
```js
const history = await store.company.getHistory(42);
// => [{ id, companyuserId, date, text }]
const recent = await store.company.getHistory(42, { limit: 5 });
// => up to 5 most recent entries
```
## `company.list`
*Source: `src/store/company/list.js`*
Lists the companies accessible to the given Google auth user.
**Parameters**
| Name | Type | Description |
| --- | --- | --- |
| `googleAuthId` | `number` | The id of the Google auth user. |
| `[tx]` | `object` | Optional transaction to run within. |
**Returns**
`Promise<Array<{id: number, name: string, rootCategoryId: number, languageId: number, iso639: string|null, taxrate: number, reducedtaxrate: number, taxfreerate: number}>>` — The accessible company rows.
**Example**
```js
const companies = await store.company.list(42);
// => [{ id, name, rootCategoryId, languageId, iso639, taxrate, reducedtaxrate, taxfreerate }]
```
## `company.update`
*Source: `src/store/company/update.js`*
Updates an existing company's name, language and tax rates.
**Parameters**
| Name | Type | Description |
| --- | --- | --- |
| `id` | `number` | The id of the company to update. |
| `input` | `object` | The update input. |
| `input.iso639` | `string` | The ISO 639 language code. |
| `input.name` | `string` | The new company name. |
| `input.taxrate` | `number` | The standard tax rate in percent. |
| `input.reducedtaxrate` | `number` | The reduced tax rate in percent. |
| `[tx]` | `object` | Optional transaction to run within. |
**Returns**
`Promise<{id: number, rootCategoryId: number, languageId: number, taxrateId: number, reducedtaxrateId: number, taxfreerateId: number}>` — The updated company ids.
**Throws**
`Error` — If the company is not found.
**Example**
```js
const result = await store.company.update(1, { iso639: 'de', name: 'Acme', taxrate: 19, reducedtaxrate: 7 });
// => { id, rootCategoryId, languageId, taxrateId, reducedtaxrateId, taxfreerateId }
```