This commit is contained in:
seb
2026-08-07 05:21:56 +02:00
parent 70e0a9ddc4
commit 396389457f
22 changed files with 225 additions and 242 deletions

View File

@@ -9,8 +9,7 @@ This document is auto-generated from the JSDoc comments in `src/store` by runnin
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.
```js
const fn = create(pool);
const company = await fn({
const company = await store.company.create({
iso639: 'de',
name: 'Acme',
taxrate: 19,
@@ -27,8 +26,7 @@ const company = await fn({
Deletes a company by its id.
```js
const fn = del(pool);
await fn(1);
await store.company.delete(1);
```
## `company.getById`
@@ -38,8 +36,7 @@ await fn(1);
Returns a single company by its id.
```js
const fn = getById(pool);
const company = await fn(1);
const company = await store.company.getById(1);
// => { id, name, ... }
```
@@ -50,8 +47,7 @@ const company = await fn(1);
Returns a single company by its name.
```js
const fn = getByName(pool);
const company = await fn('Acme');
const company = await store.company.getByName('Acme');
// => { id, name, ... }
```
@@ -62,8 +58,7 @@ const company = await fn('Acme');
Lists the companies accessible to the given Google auth user.
```js
const fn = list(pool);
const companies = await fn(42);
const companies = await store.company.list(42);
// => [{ id, name, ... }]
```
@@ -74,7 +69,6 @@ const companies = await fn(42);
Updates an existing company's name, language and tax rates.
```js
const fn = update(pool);
const result = await fn(1, { iso639: 'de', name: 'Acme', taxrate: 19, reducedtaxrate: 7 });
const result = await store.company.update(1, { iso639: 'de', name: 'Acme', taxrate: 19, reducedtaxrate: 7 });
// => { id, rootCategoryId, languageId, taxrateId, reducedtaxrateId, taxfreerateId }
```

View File

@@ -9,8 +9,7 @@ This document is auto-generated from the JSDoc comments in `src/store` by runnin
Adds a company user linking a company to a Google auth account.
```js
const fn = add(pool);
const id = await fn(1, 42);
const id = await store.companyuser.add(1, 42);
// => 7
```
@@ -21,8 +20,7 @@ const id = await fn(1, 42);
Deletes a company user link by its id.
```js
const fn = del(pool);
await fn(7);
await store.companyuser.delete(7);
```
## `companyuser.getByEmail`
@@ -32,7 +30,6 @@ await fn(7);
Returns the company user ids associated with the given email address.
```js
const fn = getByEmail(pool);
const ids = await fn('user@example.com');
const ids = await store.companyuser.getByEmail('user@example.com');
// => [1, 2, 3]
```

View File

@@ -9,8 +9,7 @@ This document is auto-generated from the JSDoc comments in `src/store` by runnin
Creates a new language by its ISO 639 code.
```js
const fn = create(pool);
const id = await fn('de');
const id = await store.lang.create('de');
// => 1
```
@@ -21,8 +20,7 @@ const id = await fn('de');
Deletes a language by its id.
```js
const fn = del(pool);
await fn(1);
await store.lang.delete(1);
```
## `lang.ensure`
@@ -32,8 +30,7 @@ await fn(1);
Returns the id of a language by ISO code, creating it if it does not exist.
```js
const fn = ensure(pool);
const id = await fn('de');
const id = await store.lang.ensure('de');
// => 1
```
@@ -44,9 +41,8 @@ const id = await fn('de');
Returns a language row by its ISO 639 code.
```js
const fn = getByIso639(pool);
const lang = await fn('de');
// => { id, iso639 }
const lang = await store.lang.getByIso639('de');
// => { id: 1, iso639: 'de' }
```
## `lang.list`
@@ -56,7 +52,6 @@ const lang = await fn('de');
Lists all languages.
```js
const fn = list(pool);
const languages = await fn();
// => [{ id, iso639 }]
const languages = await store.lang.list();
// => [{ id: 1, iso639: 'de' }]
```

View File

@@ -9,8 +9,7 @@ This document is auto-generated from the JSDoc comments in `src/store` by runnin
Creates a new tax rate.
```js
const fn = create(pool);
const id = await fn(19);
const id = await store.tax.create(19);
// => 1
```
@@ -21,8 +20,7 @@ const id = await fn(19);
Returns the id of a tax rate, creating it if it does not exist.
```js
const fn = ensure(pool);
const id = await fn(19);
const id = await store.tax.ensure(19);
// => 1
```
@@ -33,9 +31,8 @@ const id = await fn(19);
Returns a tax row by its rate.
```js
const fn = getByRate(pool);
const tax = await fn(19);
// => { id, rate }
const tax = await store.tax.getByRate(19);
// => { id: 1, rate: 19 }
```
## `tax.list`
@@ -45,7 +42,6 @@ const tax = await fn(19);
Lists all tax rates.
```js
const fn = list(pool);
const taxes = await fn();
// => [{ id, rate }]
const taxes = await store.tax.list();
// => [{ id: 1, rate: 19 }]
```

View File

@@ -11,16 +11,26 @@ import langEnsure from '../lang/ensure.js';
import taxEnsure from '../tax/ensure.js';
import request from '../request.js';
/**
export default function create(pool) {
const nameTaken = getByName(pool);
const ensureLang = langEnsure(pool);
const ensureTax = taxEnsure(pool);
/**
* 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.
*
* @param {object} pool - The mssql connection pool.
* @returns {Function} An async function that creates a company.
* @param {object} input - The company creation input.
* @param {string} input.iso639 - The ISO 639 language code for the company.
* @param {string} input.name - The company name (must be unique).
* @param {number} input.taxrate - The standard tax rate in percent.
* @param {number} input.reducedtaxrate - The reduced tax rate in percent.
* @param {number} input.googleAuthId - The id of the Google auth user to link.
* @returns {Promise<{id: number, rootCategoryId: number, languageId: number, taxrateId: number, reducedtaxrateId: number, taxfreerateId: number, posCustomerGroupId: number}>} The created company ids.
* @throws {Error} If the company name is already taken.
*
* @example
* const fn = create(pool);
* const company = await fn({
* const company = await store.company.create({
* iso639: 'de',
* name: 'Acme',
* taxrate: 19,
@@ -29,11 +39,6 @@ import request from '../request.js';
* });
* // => { id, rootCategoryId, languageId, taxrateId, reducedtaxrateId, taxfreerateId, posCustomerGroupId }
*/
export default function create(pool) {
const nameTaken = getByName(pool);
const ensureLang = langEnsure(pool);
const ensureTax = taxEnsure(pool);
return async ({ iso639, name, taxrate, reducedtaxrate, googleAuthId }) => {
const tx = pool.transaction();
await tx.begin();

View File

@@ -1,16 +1,15 @@
import { DELETE } from '../../sql/company.js';
/**
export default function del(pool) {
/**
* Deletes a company by its id.
*
* @param {object} pool - The mssql connection pool.
* @returns {Function} An async function that deletes a company.
* @param {number} companyId - The id of the company to delete.
* @returns {Promise<void>}
*
* @example
* const fn = del(pool);
* await fn(1);
* await store.company.delete(1);
*/
export default function del(pool) {
return async (companyId) => {
await pool
.request()

View File

@@ -1,18 +1,18 @@
import { GET_BY_ID } from '../../sql/company.js';
import request from '../request.js';
/**
export default function getById(pool) {
/**
* Returns a single company by its id.
*
* @param {object} pool - The mssql connection pool.
* @returns {Function} An async function that fetches a company by id.
* @param {number} id - The id of the company.
* @param {object} [tx] - Optional transaction to run within.
* @returns {Promise<object|undefined>} The company row, or `undefined` if not found.
*
* @example
* const fn = getById(pool);
* const company = await fn(1);
* const company = await store.company.getById(1);
* // => { id, name, ... }
*/
export default function getById(pool) {
return async (id, tx) => {
const result = await request(pool, tx)
.input('id', id)

View File

@@ -1,18 +1,18 @@
import { GET_BY_NAME } from '../../sql/company.js';
import request from '../request.js';
/**
export default function getByName(pool) {
/**
* Returns a single company by its name.
*
* @param {object} pool - The mssql connection pool.
* @returns {Function} An async function that fetches a company by name.
* @param {string} name - The company name.
* @param {object} [tx] - Optional transaction to run within.
* @returns {Promise<object|undefined>} The company row, or `undefined` if not found.
*
* @example
* const fn = getByName(pool);
* const company = await fn('Acme');
* const company = await store.company.getByName('Acme');
* // => { id, name, ... }
*/
export default function getByName(pool) {
return async (name, tx) => {
const result = await request(pool, tx)
.input('name', name)

View File

@@ -1,17 +1,16 @@
import { LIST } from '../../sql/company.js';
/**
export default function list(pool) {
/**
* Lists the companies accessible to the given Google auth user.
*
* @param {object} pool - The mssql connection pool.
* @returns {Function} An async function that lists companies.
* @param {number} googleAuthId - The id of the Google auth user.
* @returns {Promise<Array<object>>} The accessible company rows.
*
* @example
* const fn = list(pool);
* const companies = await fn(42);
* const companies = await store.company.list(42);
* // => [{ id, name, ... }]
*/
export default function list(pool) {
return async (googleAuthId) => {
const result = await pool
.request()

View File

@@ -5,23 +5,28 @@ import langEnsure from '../lang/ensure.js';
import taxEnsure from '../tax/ensure.js';
import request from '../request.js';
/**
* Updates an existing company's name, language and tax rates.
*
* @param {object} pool - The mssql connection pool.
* @returns {Function} An async function that updates a company.
*
* @example
* const fn = update(pool);
* const result = await fn(1, { iso639: 'de', name: 'Acme', taxrate: 19, reducedtaxrate: 7 });
* // => { id, rootCategoryId, languageId, taxrateId, reducedtaxrateId, taxfreerateId }
*/
export default function update(pool) {
const byId = getById(pool);
const byName = getByName(pool);
const ensureLang = langEnsure(pool);
const ensureTax = taxEnsure(pool);
/**
* Updates an existing company's name, language and tax rates.
*
* @param {number} id - The id of the company to update.
* @param {object} input - The update input.
* @param {string} input.iso639 - The ISO 639 language code.
* @param {string} input.name - The new company name (must be unique).
* @param {number} input.taxrate - The standard tax rate in percent.
* @param {number} input.reducedtaxrate - The reduced tax rate in percent.
* @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 or the name is taken.
*
* @example
* const result = await store.company.update(1, { iso639: 'de', name: 'Acme', taxrate: 19, reducedtaxrate: 7 });
* // => { id, rootCategoryId, languageId, taxrateId, reducedtaxrateId, taxfreerateId }
*/
return async (id, { iso639, name, taxrate, reducedtaxrate }) => {
const tx = pool.transaction();
await tx.begin();

View File

@@ -1,17 +1,17 @@
import { ADD } from '../../sql/companyuser.js';
/**
export default function add(pool) {
/**
* Adds a company user linking a company to a Google auth account.
*
* @param {object} pool - The mssql connection pool.
* @returns {Function} An async function that creates the company user link.
* @param {number} companyId - The id of the company.
* @param {number} googleAuthId - The id of the Google auth account.
* @returns {Promise<number>} The id of the created company user link.
*
* @example
* const fn = add(pool);
* const id = await fn(1, 42);
* const id = await store.companyuser.add(1, 42);
* // => 7
*/
export default function add(pool) {
return async (companyId, googleAuthId) => {
const result = await pool
.request()

View File

@@ -1,16 +1,15 @@
import { DELETE } from '../../sql/companyuser.js';
/**
export default function del(pool) {
/**
* Deletes a company user link by its id.
*
* @param {object} pool - The mssql connection pool.
* @returns {Function} An async function that removes the company user link.
* @param {number} id - The id of the company user link to delete.
* @returns {Promise<void>}
*
* @example
* const fn = del(pool);
* await fn(7);
* await store.companyuser.delete(7);
*/
export default function del(pool) {
return async (id) => {
await pool
.request()

View File

@@ -1,17 +1,16 @@
import { GET_BY_EMAIL } from '../../sql/companyuser.js';
/**
export default function getByEmail(pool) {
/**
* Returns the company user ids associated with the given email address.
*
* @param {object} pool - The mssql connection pool.
* @returns {Function} An async function that resolves the company user ids for an email.
* @param {string} email - The email address.
* @returns {Promise<Array<number>>} The company user ids.
*
* @example
* const fn = getByEmail(pool);
* const ids = await fn('user@example.com');
* const ids = await store.companyuser.getByEmail('user@example.com');
* // => [1, 2, 3]
*/
export default function getByEmail(pool) {
return async (email) => {
const result = await pool
.request()

View File

@@ -1,18 +1,18 @@
import { CREATE } from '../../sql/language.js';
import request from '../request.js';
/**
export default function create(pool) {
/**
* Creates a new language by its ISO 639 code.
*
* @param {object} pool - The mssql connection pool.
* @returns {Function} An async function that creates a language.
* @param {string} iso639 - The ISO 639 language code (e.g. `'de'`).
* @param {object} [tx] - Optional transaction to run within.
* @returns {Promise<number>} The id of the created language.
*
* @example
* const fn = create(pool);
* const id = await fn('de');
* const id = await store.lang.create('de');
* // => 1
*/
export default function create(pool) {
return async (iso639, tx) => {
const result = await request(pool, tx)
.input('iso639', iso639)

View File

@@ -1,16 +1,15 @@
import { DELETE } from '../../sql/language.js';
/**
export default function del(pool) {
/**
* Deletes a language by its id.
*
* @param {object} pool - The mssql connection pool.
* @returns {Function} An async function that deletes a language.
* @param {number} id - The id of the language to delete.
* @returns {Promise<void>}
*
* @example
* const fn = del(pool);
* await fn(1);
* await store.lang.delete(1);
*/
export default function del(pool) {
return async (id) => {
await pool
.request()

View File

@@ -1,20 +1,20 @@
import getByIso639 from './getByIso639.js';
import create from './create.js';
/**
* Returns the id of a language by ISO code, creating it if it does not exist.
*
* @param {object} pool - The mssql connection pool.
* @returns {Function} An async function that ensures a language exists.
*
* @example
* const fn = ensure(pool);
* const id = await fn('de');
* // => 1
*/
export default function ensure(pool) {
const get = getByIso639(pool);
const add = create(pool);
/**
* Returns the id of a language by ISO code, creating it if it does not exist.
*
* @param {string} iso639 - The ISO 639 language code (e.g. `'de'`).
* @param {object} [tx] - Optional transaction to run within.
* @returns {Promise<number>} The id of the language.
*
* @example
* const id = await store.lang.ensure('de');
* // => 1
*/
return async (iso639, tx) => {
const row = await get(iso639, tx);
if (row) return row.id;

View File

@@ -1,18 +1,18 @@
import { GET_BY_ISO639 } from '../../sql/language.js';
import request from '../request.js';
/**
export default function getByIso639(pool) {
/**
* Returns a language row by its ISO 639 code.
*
* @param {object} pool - The mssql connection pool.
* @returns {Function} An async function that fetches a language by ISO code.
* @param {string} iso639 - The ISO 639 language code (e.g. `'de'`).
* @param {object} [tx] - Optional transaction to run within.
* @returns {Promise<{id: number, iso639: string}>} The language row, or `undefined` if not found.
*
* @example
* const fn = getByIso639(pool);
* const lang = await fn('de');
* // => { id, iso639 }
* const lang = await store.lang.getByIso639('de');
* // => { id: 1, iso639: 'de' }
*/
export default function getByIso639(pool) {
return async (iso639, tx) => {
const result = await request(pool, tx)
.input('iso639', iso639)

View File

@@ -1,17 +1,15 @@
import { LIST } from '../../sql/language.js';
/**
export default function list(pool) {
/**
* Lists all languages.
*
* @param {object} pool - The mssql connection pool.
* @returns {Function} An async function that lists languages.
* @returns {Promise<Array<{id: number, iso639: string}>>} All language rows.
*
* @example
* const fn = list(pool);
* const languages = await fn();
* // => [{ id, iso639 }]
* const languages = await store.lang.list();
* // => [{ id: 1, iso639: 'de' }]
*/
export default function list(pool) {
return async () => {
const result = await pool.request().query(LIST);
return result.recordset;

View File

@@ -1,18 +1,18 @@
import { CREATE } from '../../sql/tax.js';
import request from '../request.js';
/**
export default function create(pool) {
/**
* Creates a new tax rate.
*
* @param {object} pool - The mssql connection pool.
* @returns {Function} An async function that creates a tax rate.
* @param {number} rate - The tax rate in percent (e.g. `19`).
* @param {object} [tx] - Optional transaction to run within.
* @returns {Promise<number>} The id of the created tax rate.
*
* @example
* const fn = create(pool);
* const id = await fn(19);
* const id = await store.tax.create(19);
* // => 1
*/
export default function create(pool) {
return async (rate, tx) => {
const result = await request(pool, tx)
.input('rate', rate)

View File

@@ -1,20 +1,20 @@
import getByRate from './getByRate.js';
import create from './create.js';
/**
* Returns the id of a tax rate, creating it if it does not exist.
*
* @param {object} pool - The mssql connection pool.
* @returns {Function} An async function that ensures a tax rate exists.
*
* @example
* const fn = ensure(pool);
* const id = await fn(19);
* // => 1
*/
export default function ensure(pool) {
const get = getByRate(pool);
const add = create(pool);
/**
* Returns the id of a tax rate, creating it if it does not exist.
*
* @param {number} rate - The tax rate in percent (e.g. `19`).
* @param {object} [tx] - Optional transaction to run within.
* @returns {Promise<number>} The id of the tax rate.
*
* @example
* const id = await store.tax.ensure(19);
* // => 1
*/
return async (rate, tx) => {
const row = await get(rate, tx);
if (row) return row.id;

View File

@@ -1,18 +1,18 @@
import { GET_BY_RATE } from '../../sql/tax.js';
import request from '../request.js';
/**
export default function getByRate(pool) {
/**
* Returns a tax row by its rate.
*
* @param {object} pool - The mssql connection pool.
* @returns {Function} An async function that fetches a tax rate.
* @param {number} rate - The tax rate in percent (e.g. `19`).
* @param {object} [tx] - Optional transaction to run within.
* @returns {Promise<{id: number, rate: number}>} The tax row, or `undefined` if not found.
*
* @example
* const fn = getByRate(pool);
* const tax = await fn(19);
* // => { id, rate }
* const tax = await store.tax.getByRate(19);
* // => { id: 1, rate: 19 }
*/
export default function getByRate(pool) {
return async (rate, tx) => {
const result = await request(pool, tx)
.input('rate', rate)

View File

@@ -1,17 +1,15 @@
import { LIST } from '../../sql/tax.js';
/**
export default function list(pool) {
/**
* Lists all tax rates.
*
* @param {object} pool - The mssql connection pool.
* @returns {Function} An async function that lists tax rates.
* @returns {Promise<Array<{id: number, rate: number}>>} All tax rate rows.
*
* @example
* const fn = list(pool);
* const taxes = await fn();
* // => [{ id, rate }]
* const taxes = await store.tax.list();
* // => [{ id: 1, rate: 19 }]
*/
export default function list(pool) {
return async () => {
const result = await pool.request().query(LIST);
return result.recordset;