Add entity customer numbers and scope APIs via selected company.

Entity gets an optional unique-per-company number with allocate/peek/isNumberFree helpers. Company-scoped store methods no longer take companyId and resolve google_auth.selected_company instead.
This commit is contained in:
seb
2026-08-07 04:29:35 +02:00
parent 1e89e19863
commit 70e0a9ddc4
78 changed files with 940 additions and 772 deletions

View File

@@ -6,12 +6,12 @@ This document is auto-generated from the JSDoc comments in `src/store` by runnin
*Source: `src/store/entity/create.js`*
Creates a new entity (customer) in a customer group, recording history.
Creates a new entity (customer) in a customer group, recording history. Optional `number`; if omitted, allocates via `getnextnumberwithprefixandpadding` (`type` `entity`).
```js
const fn = create(pool);
const entity = await fn(42, 1, { customergroupId: 5, name: 'Doe', firstName: 'John' });
// => { id, customergroupId, firstName, name, createdAt, updatedAt }
const entity = await fn(42, { customergroupId: 5, name: 'Doe', firstName: 'John' });
// => { id, customergroupId, firstName, name, number, createdAt, updatedAt }
```
## `entity.delete`
@@ -22,7 +22,7 @@ Deletes an entity by its id within a company.
```js
const fn = del(pool);
await fn(42, 1, 5);
await fn(42, 5);
```
## `entity.getById`
@@ -33,8 +33,22 @@ Returns a single entity by its id within a company.
```js
const fn = getById(pool);
const entity = await fn(42, 1, 5);
// => { id, customergroupId, firstName, name, createdAt, updatedAt }
const entity = await fn(42, 5);
// => { id, customergroupId, firstName, name, number, createdAt, updatedAt }
```
## `entity.isNumberFree`
*Source: `src/store/entity/isNumberFree.js`*
Returns whether a customer number is free within the company. Pass `excludeEntityId` when editing so the entity's own number counts as free.
```js
const fn = isNumberFree(pool);
const free = await fn(42, 'C-100');
// => true
const freeOnEdit = await fn(42, 'C-100', { excludeEntityId: 5 });
// => true
```
## `entity.list`
@@ -45,18 +59,30 @@ Lists the entities (customers) of a company, optionally filtered by customer gro
```js
const fn = list(pool);
const entities = await fn(42, 1, { customergroupId: 5 });
// => [{ id, customergroupId, firstName, name, createdAt, updatedAt }]
const entities = await fn(42, { customergroupId: 5 });
// => [{ id, customergroupId, firstName, name, number, createdAt, updatedAt }]
```
## `entity.peekNextNumber`
*Source: `src/store/entity/peekNextNumber.js`*
Returns the next customer number that would be allocated for the company (`numbers` type `entity`) without consuming it.
```js
const fn = peekNextNumber(pool);
const number = await fn(42);
// => '1'
```
## `entity.update`
*Source: `src/store/entity/update.js`*
Updates the name and/or first name of an entity, recording history.
Updates name, first name, and/or customer number of an entity, recording history. Optional `number` sets the customer number explicitly (does not auto-allocate).
```js
const fn = update(pool);
const entity = await fn(42, 1, 5, { name: 'Doe', firstName: 'Jane' });
// => { id, customergroupId, firstName, name, createdAt, updatedAt }
const entity = await fn(42, 5, { name: 'Doe', firstName: 'Jane', number: 'C-42' });
// => { id, customergroupId, firstName, name, number, createdAt, updatedAt }
```