Files
dashlibstorage/API.entity.md
seb 70e0a9ddc4 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.
2026-08-07 04:29:35 +02:00

2.3 KiB

entity

This document is auto-generated from the JSDoc comments in src/store by running npm run api-doc.

entity.create

Source: src/store/entity/create.js

Creates a new entity (customer) in a customer group, recording history. Optional number; if omitted, allocates via getnextnumberwithprefixandpadding (type entity).

const fn = create(pool);
const entity = await fn(42, { customergroupId: 5, name: 'Doe', firstName: 'John' });
// => { id, customergroupId, firstName, name, number, createdAt, updatedAt }

entity.delete

Source: src/store/entity/delete.js

Deletes an entity by its id within a company.

const fn = del(pool);
await fn(42, 5);

entity.getById

Source: src/store/entity/getById.js

Returns a single entity by its id within a company.

const fn = getById(pool);
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.

const fn = isNumberFree(pool);
const free = await fn(42, 'C-100');
// => true
const freeOnEdit = await fn(42, 'C-100', { excludeEntityId: 5 });
// => true

entity.list

Source: src/store/entity/list.js

Lists the entities (customers) of a company, optionally filtered by customer group or restricted to the 'customer' role.

const fn = list(pool);
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.

const fn = peekNextNumber(pool);
const number = await fn(42);
// => '1'

entity.update

Source: src/store/entity/update.js

Updates name, first name, and/or customer number of an entity, recording history. Optional number sets the customer number explicitly (does not auto-allocate).

const fn = update(pool);
const entity = await fn(42, 5, { name: 'Doe', firstName: 'Jane', number: 'C-42' });
// => { id, customergroupId, firstName, name, number, createdAt, updatedAt }