diff --git a/API.company.md b/API.company.md index 7e8e468..2d3296c 100644 --- a/API.company.md +++ b/API.company.md @@ -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 } ``` diff --git a/API.companyuser.md b/API.companyuser.md index 22f3606..b104706 100644 --- a/API.companyuser.md +++ b/API.companyuser.md @@ -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] ``` diff --git a/API.lang.md b/API.lang.md index 5d20b48..31250f8 100644 --- a/API.lang.md +++ b/API.lang.md @@ -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' }] ``` diff --git a/API.tax.md b/API.tax.md index d6f77c4..40462b7 100644 --- a/API.tax.md +++ b/API.tax.md @@ -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 }] ``` diff --git a/src/store/company/create.js b/src/store/company/create.js index b3e9e53..947ede0 100644 --- a/src/store/company/create.js +++ b/src/store/company/create.js @@ -11,29 +11,34 @@ import langEnsure from '../lang/ensure.js'; import taxEnsure from '../tax/ensure.js'; import request from '../request.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. - * - * @param {object} pool - The mssql connection pool. - * @returns {Function} An async function that creates a company. - * - * @example - * const fn = create(pool); - * const company = await fn({ - * iso639: 'de', - * name: 'Acme', - * taxrate: 19, - * reducedtaxrate: 7, - * googleAuthId: 42, - * }); - * // => { id, rootCategoryId, languageId, taxrateId, reducedtaxrateId, taxfreerateId, posCustomerGroupId } - */ 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} 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 company = await store.company.create({ + * iso639: 'de', + * name: 'Acme', + * taxrate: 19, + * reducedtaxrate: 7, + * googleAuthId: 42, + * }); + * // => { id, rootCategoryId, languageId, taxrateId, reducedtaxrateId, taxfreerateId, posCustomerGroupId } + */ return async ({ iso639, name, taxrate, reducedtaxrate, googleAuthId }) => { const tx = pool.transaction(); await tx.begin(); diff --git a/src/store/company/delete.js b/src/store/company/delete.js index 283f4ca..6477bd8 100644 --- a/src/store/company/delete.js +++ b/src/store/company/delete.js @@ -1,16 +1,15 @@ import { DELETE } from '../../sql/company.js'; -/** - * Deletes a company by its id. - * - * @param {object} pool - The mssql connection pool. - * @returns {Function} An async function that deletes a company. - * - * @example - * const fn = del(pool); - * await fn(1); - */ export default function del(pool) { + /** + * Deletes a company by its id. + * + * @param {number} companyId - The id of the company to delete. + * @returns {Promise} + * + * @example + * await store.company.delete(1); + */ return async (companyId) => { await pool .request() diff --git a/src/store/company/getById.js b/src/store/company/getById.js index 04b35fb..1468282 100644 --- a/src/store/company/getById.js +++ b/src/store/company/getById.js @@ -1,18 +1,18 @@ import { GET_BY_ID } from '../../sql/company.js'; import request from '../request.js'; -/** - * 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. - * - * @example - * const fn = getById(pool); - * const company = await fn(1); - * // => { id, name, ... } - */ export default function getById(pool) { + /** + * Returns a single company by its id. + * + * @param {number} id - The id of the company. + * @param {object} [tx] - Optional transaction to run within. + * @returns {Promise} The company row, or `undefined` if not found. + * + * @example + * const company = await store.company.getById(1); + * // => { id, name, ... } + */ return async (id, tx) => { const result = await request(pool, tx) .input('id', id) diff --git a/src/store/company/getByName.js b/src/store/company/getByName.js index 3197c7f..1097132 100644 --- a/src/store/company/getByName.js +++ b/src/store/company/getByName.js @@ -1,18 +1,18 @@ import { GET_BY_NAME } from '../../sql/company.js'; import request from '../request.js'; -/** - * 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. - * - * @example - * const fn = getByName(pool); - * const company = await fn('Acme'); - * // => { id, name, ... } - */ export default function getByName(pool) { + /** + * Returns a single company by its name. + * + * @param {string} name - The company name. + * @param {object} [tx] - Optional transaction to run within. + * @returns {Promise} The company row, or `undefined` if not found. + * + * @example + * const company = await store.company.getByName('Acme'); + * // => { id, name, ... } + */ return async (name, tx) => { const result = await request(pool, tx) .input('name', name) diff --git a/src/store/company/list.js b/src/store/company/list.js index 7ef868b..2a0a41c 100644 --- a/src/store/company/list.js +++ b/src/store/company/list.js @@ -1,17 +1,16 @@ import { LIST } from '../../sql/company.js'; -/** - * 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. - * - * @example - * const fn = list(pool); - * const companies = await fn(42); - * // => [{ id, name, ... }] - */ export default function list(pool) { + /** + * Lists the companies accessible to the given Google auth user. + * + * @param {number} googleAuthId - The id of the Google auth user. + * @returns {Promise>} The accessible company rows. + * + * @example + * const companies = await store.company.list(42); + * // => [{ id, name, ... }] + */ return async (googleAuthId) => { const result = await pool .request() diff --git a/src/store/company/update.js b/src/store/company/update.js index 5849590..f5b17f0 100644 --- a/src/store/company/update.js +++ b/src/store/company/update.js @@ -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(); diff --git a/src/store/companyuser/add.js b/src/store/companyuser/add.js index 085fb53..29cedd2 100644 --- a/src/store/companyuser/add.js +++ b/src/store/companyuser/add.js @@ -1,17 +1,17 @@ import { ADD } from '../../sql/companyuser.js'; -/** - * 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. - * - * @example - * const fn = add(pool); - * const id = await fn(1, 42); - * // => 7 - */ export default function add(pool) { + /** + * Adds a company user linking a company to a Google auth account. + * + * @param {number} companyId - The id of the company. + * @param {number} googleAuthId - The id of the Google auth account. + * @returns {Promise} The id of the created company user link. + * + * @example + * const id = await store.companyuser.add(1, 42); + * // => 7 + */ return async (companyId, googleAuthId) => { const result = await pool .request() diff --git a/src/store/companyuser/delete.js b/src/store/companyuser/delete.js index 0d5f28f..f0b5ffe 100644 --- a/src/store/companyuser/delete.js +++ b/src/store/companyuser/delete.js @@ -1,16 +1,15 @@ import { DELETE } from '../../sql/companyuser.js'; -/** - * 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. - * - * @example - * const fn = del(pool); - * await fn(7); - */ export default function del(pool) { + /** + * Deletes a company user link by its id. + * + * @param {number} id - The id of the company user link to delete. + * @returns {Promise} + * + * @example + * await store.companyuser.delete(7); + */ return async (id) => { await pool .request() diff --git a/src/store/companyuser/getByEmail.js b/src/store/companyuser/getByEmail.js index cfcb311..ed4fd19 100644 --- a/src/store/companyuser/getByEmail.js +++ b/src/store/companyuser/getByEmail.js @@ -1,17 +1,16 @@ import { GET_BY_EMAIL } from '../../sql/companyuser.js'; -/** - * 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. - * - * @example - * const fn = getByEmail(pool); - * const ids = await fn('user@example.com'); - * // => [1, 2, 3] - */ export default function getByEmail(pool) { + /** + * Returns the company user ids associated with the given email address. + * + * @param {string} email - The email address. + * @returns {Promise>} The company user ids. + * + * @example + * const ids = await store.companyuser.getByEmail('user@example.com'); + * // => [1, 2, 3] + */ return async (email) => { const result = await pool .request() diff --git a/src/store/lang/create.js b/src/store/lang/create.js index 9e5682b..75be363 100644 --- a/src/store/lang/create.js +++ b/src/store/lang/create.js @@ -1,18 +1,18 @@ import { CREATE } from '../../sql/language.js'; import request from '../request.js'; -/** - * 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. - * - * @example - * const fn = create(pool); - * const id = await fn('de'); - * // => 1 - */ export default function create(pool) { + /** + * Creates a new language by its ISO 639 code. + * + * @param {string} iso639 - The ISO 639 language code (e.g. `'de'`). + * @param {object} [tx] - Optional transaction to run within. + * @returns {Promise} The id of the created language. + * + * @example + * const id = await store.lang.create('de'); + * // => 1 + */ return async (iso639, tx) => { const result = await request(pool, tx) .input('iso639', iso639) diff --git a/src/store/lang/delete.js b/src/store/lang/delete.js index 14fe0e9..897b851 100644 --- a/src/store/lang/delete.js +++ b/src/store/lang/delete.js @@ -1,16 +1,15 @@ import { DELETE } from '../../sql/language.js'; -/** - * Deletes a language by its id. - * - * @param {object} pool - The mssql connection pool. - * @returns {Function} An async function that deletes a language. - * - * @example - * const fn = del(pool); - * await fn(1); - */ export default function del(pool) { + /** + * Deletes a language by its id. + * + * @param {number} id - The id of the language to delete. + * @returns {Promise} + * + * @example + * await store.lang.delete(1); + */ return async (id) => { await pool .request() diff --git a/src/store/lang/ensure.js b/src/store/lang/ensure.js index 36db379..fbb4c32 100644 --- a/src/store/lang/ensure.js +++ b/src/store/lang/ensure.js @@ -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} 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; diff --git a/src/store/lang/getByIso639.js b/src/store/lang/getByIso639.js index 4a72a72..93ccdb5 100644 --- a/src/store/lang/getByIso639.js +++ b/src/store/lang/getByIso639.js @@ -1,18 +1,18 @@ import { GET_BY_ISO639 } from '../../sql/language.js'; import request from '../request.js'; -/** - * 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. - * - * @example - * const fn = getByIso639(pool); - * const lang = await fn('de'); - * // => { id, iso639 } - */ export default function getByIso639(pool) { + /** + * Returns a language row by its ISO 639 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 lang = await store.lang.getByIso639('de'); + * // => { id: 1, iso639: 'de' } + */ return async (iso639, tx) => { const result = await request(pool, tx) .input('iso639', iso639) diff --git a/src/store/lang/list.js b/src/store/lang/list.js index ae4ecdd..792dc95 100644 --- a/src/store/lang/list.js +++ b/src/store/lang/list.js @@ -1,17 +1,15 @@ import { LIST } from '../../sql/language.js'; -/** - * Lists all languages. - * - * @param {object} pool - The mssql connection pool. - * @returns {Function} An async function that lists languages. - * - * @example - * const fn = list(pool); - * const languages = await fn(); - * // => [{ id, iso639 }] - */ export default function list(pool) { + /** + * Lists all languages. + * + * @returns {Promise>} All language rows. + * + * @example + * const languages = await store.lang.list(); + * // => [{ id: 1, iso639: 'de' }] + */ return async () => { const result = await pool.request().query(LIST); return result.recordset; diff --git a/src/store/tax/create.js b/src/store/tax/create.js index 34320c7..1b5bbf5 100644 --- a/src/store/tax/create.js +++ b/src/store/tax/create.js @@ -1,18 +1,18 @@ import { CREATE } from '../../sql/tax.js'; import request from '../request.js'; -/** - * Creates a new tax rate. - * - * @param {object} pool - The mssql connection pool. - * @returns {Function} An async function that creates a tax rate. - * - * @example - * const fn = create(pool); - * const id = await fn(19); - * // => 1 - */ export default function create(pool) { + /** + * Creates a new tax rate. + * + * @param {number} rate - The tax rate in percent (e.g. `19`). + * @param {object} [tx] - Optional transaction to run within. + * @returns {Promise} The id of the created tax rate. + * + * @example + * const id = await store.tax.create(19); + * // => 1 + */ return async (rate, tx) => { const result = await request(pool, tx) .input('rate', rate) diff --git a/src/store/tax/ensure.js b/src/store/tax/ensure.js index 37f5494..0f8cd58 100644 --- a/src/store/tax/ensure.js +++ b/src/store/tax/ensure.js @@ -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} 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; diff --git a/src/store/tax/getByRate.js b/src/store/tax/getByRate.js index f1f5f2a..c76aae7 100644 --- a/src/store/tax/getByRate.js +++ b/src/store/tax/getByRate.js @@ -1,18 +1,18 @@ import { GET_BY_RATE } from '../../sql/tax.js'; import request from '../request.js'; -/** - * Returns a tax row by its rate. - * - * @param {object} pool - The mssql connection pool. - * @returns {Function} An async function that fetches a tax rate. - * - * @example - * const fn = getByRate(pool); - * const tax = await fn(19); - * // => { id, rate } - */ export default function getByRate(pool) { + /** + * Returns a tax row by its 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 tax = await store.tax.getByRate(19); + * // => { id: 1, rate: 19 } + */ return async (rate, tx) => { const result = await request(pool, tx) .input('rate', rate) diff --git a/src/store/tax/list.js b/src/store/tax/list.js index 23187f2..28ec6a1 100644 --- a/src/store/tax/list.js +++ b/src/store/tax/list.js @@ -1,17 +1,15 @@ import { LIST } from '../../sql/tax.js'; -/** - * Lists all tax rates. - * - * @param {object} pool - The mssql connection pool. - * @returns {Function} An async function that lists tax rates. - * - * @example - * const fn = list(pool); - * const taxes = await fn(); - * // => [{ id, rate }] - */ export default function list(pool) { + /** + * Lists all tax rates. + * + * @returns {Promise>} All tax rate rows. + * + * @example + * const taxes = await store.tax.list(); + * // => [{ id: 1, rate: 19 }] + */ return async () => { const result = await pool.request().query(LIST); return result.recordset;