diff --git a/src/store/article/addImage.js b/src/store/article/addImage.js index 7a01e11..7a06d5c 100644 --- a/src/store/article/addImage.js +++ b/src/store/article/addImage.js @@ -5,6 +5,17 @@ import newFullHash from '../../util/newFullHash.js'; import request from '../request.js'; import resolveArticleBySku from './resolveArticleBySku.js'; +/** + * Adds an image to an article by its SKU, processing it into AVIF variants. + * + * @param {object} pool - The mssql connection pool. + * @returns {Function} An async function that adds an article image. + * + * @example + * const fn = addImage(pool); + * const result = await fn(42, 'SKU-1', imageBuffer); + * // => { picId, sort, full: { w, h, size }, thumb: { w, h }, fullHash, thumbHash } + */ export default function addImage(pool) { const resolve = resolveArticleBySku(pool); diff --git a/src/store/article/createUnderParent.js b/src/store/article/createUnderParent.js index a4bc01d..a47ab88 100644 --- a/src/store/article/createUnderParent.js +++ b/src/store/article/createUnderParent.js @@ -7,6 +7,18 @@ import nextSku from '../numbers/nextSku.js'; import request from '../request.js'; import slugify from '../slugify.js'; +/** + * Creates a new article under a given parent category, allocating a SKU and + * a default unit. + * + * @param {object} pool - The mssql connection pool. + * @returns {Function} An async function that creates an article. + * + * @example + * const fn = createUnderParent(pool); + * const article = await fn({ googleAuthId: 42, parentId: 5, name: 'Cola' }); + * // => { id, parentId, name, sku } + */ export default function createUnderParent(pool) { const access = resolveCategoryAccess(pool); const ensureUnit = ensureDefaultUnit(pool); diff --git a/src/store/article/delete.js b/src/store/article/delete.js index 57004dc..0ed21bb 100644 --- a/src/store/article/delete.js +++ b/src/store/article/delete.js @@ -11,6 +11,16 @@ import { import resolveArticleBySku from './resolveArticleBySku.js'; import request from '../request.js'; +/** + * Deletes an article by its SKU, refusing when it still has children. + * + * @param {object} pool - The mssql connection pool. + * @returns {Function} An async function that deletes an article. + * + * @example + * const fn = del(pool); + * await fn(42, 'SKU-1'); + */ export default function del(pool) { const resolve = resolveArticleBySku(pool); diff --git a/src/store/article/deleteImage.js b/src/store/article/deleteImage.js index 5fda6d4..fc954a7 100644 --- a/src/store/article/deleteImage.js +++ b/src/store/article/deleteImage.js @@ -1,6 +1,16 @@ import { DELETE_BY_ARTICLE_AND_HASH } from '../../sql/pic.js'; import resolveArticleBySku from './resolveArticleBySku.js'; +/** + * Deletes an image from an article by its SKU and full image hash. + * + * @param {object} pool - The mssql connection pool. + * @returns {Function} An async function that deletes an article image. + * + * @example + * const fn = deleteImage(pool); + * await fn(42, 'SKU-1', 'abc123'); + */ export default function deleteImage(pool) { const resolve = resolveArticleBySku(pool); diff --git a/src/store/article/getBySku.js b/src/store/article/getBySku.js index 7bb9fcc..a206e1f 100644 --- a/src/store/article/getBySku.js +++ b/src/store/article/getBySku.js @@ -6,6 +6,18 @@ function parseJsonArray(raw) { return Array.isArray(arr) ? arr : []; } +/** + * Returns the full detail of an article by its SKU, including unit, brand, + * categories, photos, EANs and prices. + * + * @param {object} pool - The mssql connection pool. + * @returns {Function} An async function that fetches an article by SKU. + * + * @example + * const fn = getBySku(pool); + * const article = await fn(42, 'SKU-1'); + * // => { article: { id, sku, name, unit, brand, categoryIds, photos, eans, prices, ... } } + */ export default function getBySku(pool) { return async (googleAuthId, sku) => { const t0 = performance.now(); diff --git a/src/store/article/getHistoryBySku.js b/src/store/article/getHistoryBySku.js index 6f7ac8d..221f718 100644 --- a/src/store/article/getHistoryBySku.js +++ b/src/store/article/getHistoryBySku.js @@ -1,6 +1,17 @@ import { LIST_BY_ARTICLE_ID } from '../../sql/articlehistory.js'; import resolveArticleBySku from './resolveArticleBySku.js'; +/** + * Returns the change history of an article by its SKU. + * + * @param {object} pool - The mssql connection pool. + * @returns {Function} An async function that fetches the article history. + * + * @example + * const fn = getHistoryBySku(pool); + * const history = await fn(42, 'SKU-1'); + * // => [{ id, companyuserId, date, text }] + */ export default function getHistoryBySku(pool) { const resolve = resolveArticleBySku(pool); diff --git a/src/store/article/listExport.js b/src/store/article/listExport.js index 6f3b40e..51166de 100644 --- a/src/store/article/listExport.js +++ b/src/store/article/listExport.js @@ -10,6 +10,18 @@ function parseJsonArray(raw) { return Array.isArray(arr) ? arr : []; } +/** + * Returns articles for export, optionally scoped to a category, including + * category breadcrumbs and image hashes. + * + * @param {object} pool - The mssql connection pool. + * @returns {Function} An async function that lists articles for export. + * + * @example + * const fn = listExport(pool); + * const articles = await fn(42, 1, null); + * // => [{ id, sku, name, slug, unitSi, net, taxRate, eans, categoryBreadcrumbs, fullHashes, ... }] + */ export default function listExport(pool) { const companyAccess = resolveCompanyAccess(pool); const categoryAccess = resolveCategoryAccess(pool); diff --git a/src/store/article/listSearchIndex.js b/src/store/article/listSearchIndex.js index f2684e6..1066965 100644 --- a/src/store/article/listSearchIndex.js +++ b/src/store/article/listSearchIndex.js @@ -1,6 +1,17 @@ import { SEARCH_ARTICLES } from '../../sql/article.js'; import resolveCompanyAccess from '../companyuser/resolveCompanyAccess.js'; +/** + * Returns a lightweight search index of all articles for a company. + * + * @param {object} pool - The mssql connection pool. + * @returns {Function} An async function that lists the article search index. + * + * @example + * const fn = listSearchIndex(pool); + * const articles = await fn(42, 1); + * // => [{ id, sku, name, eans, categoryIds }] + */ export default function listSearchIndex(pool) { const access = resolveCompanyAccess(pool); diff --git a/src/store/article/orderImages.js b/src/store/article/orderImages.js index 7e9fc64..8022e33 100644 --- a/src/store/article/orderImages.js +++ b/src/store/article/orderImages.js @@ -6,6 +6,17 @@ import { import resolveArticleBySku from './resolveArticleBySku.js'; import request from '../request.js'; +/** + * Reorders the images of an article by its SKU. + * + * @param {object} pool - The mssql connection pool. + * @returns {Function} An async function that reorders article images. + * + * @example + * const fn = orderImages(pool); + * const result = await fn(42, 'SKU-1', { fullHashes: ['a', 'b'] }); + * // => { fullHashes: ['a', 'b'] } + */ export default function orderImages(pool) { const resolve = resolveArticleBySku(pool); diff --git a/src/store/article/setBrandIdBySku.js b/src/store/article/setBrandIdBySku.js index 63f1291..d441802 100644 --- a/src/store/article/setBrandIdBySku.js +++ b/src/store/article/setBrandIdBySku.js @@ -5,6 +5,17 @@ import { import queryBySku from './queryBySku.js'; import resolveArticleBySku from './resolveArticleBySku.js'; +/** + * Sets (or clears) the brand of an article by its SKU. + * + * @param {object} pool - The mssql connection pool. + * @returns {Function} An async function that sets the article brand. + * + * @example + * const fn = setBrandIdBySku(pool); + * const article = await fn(42, 'SKU-1', 3); + * // => { id, sku, name, ... } + */ export default function setBrandIdBySku(pool) { const resolve = resolveArticleBySku(pool); const load = queryBySku(pool); diff --git a/src/store/article/setCategoryIdsBySku.js b/src/store/article/setCategoryIdsBySku.js index f2bb8de..59ee97e 100644 --- a/src/store/article/setCategoryIdsBySku.js +++ b/src/store/article/setCategoryIdsBySku.js @@ -7,6 +7,17 @@ import resolveCategoryAccess from '../category/resolveCategoryAccess.js'; import queryBySku from './queryBySku.js'; import resolveArticleBySku from './resolveArticleBySku.js'; +/** + * Replaces the category membership of an article by its SKU. + * + * @param {object} pool - The mssql connection pool. + * @returns {Function} An async function that sets the article categories. + * + * @example + * const fn = setCategoryIdsBySku(pool); + * const article = await fn(42, 'SKU-1', [5, 9]); + * // => { id, sku, name, ... } + */ export default function setCategoryIdsBySku(pool) { const resolve = resolveArticleBySku(pool); const categoryAccess = resolveCategoryAccess(pool); diff --git a/src/store/article/setEansBySku.js b/src/store/article/setEansBySku.js index f10cf7e..ef0c3d0 100644 --- a/src/store/article/setEansBySku.js +++ b/src/store/article/setEansBySku.js @@ -6,6 +6,17 @@ import request from '../request.js'; import queryBySku from './queryBySku.js'; import resolveArticleBySku from './resolveArticleBySku.js'; +/** + * Replaces the EAN list of an article by its SKU. + * + * @param {object} pool - The mssql connection pool. + * @returns {Function} An async function that sets article EANs. + * + * @example + * const fn = setEansBySku(pool); + * const article = await fn(42, 'SKU-1', ['4001234567890']); + * // => { id, sku, name, ... } + */ export default function setEansBySku(pool) { const resolve = resolveArticleBySku(pool); const load = queryBySku(pool); diff --git a/src/store/article/setPricesBySku.js b/src/store/article/setPricesBySku.js index 8a42919..3084b14 100644 --- a/src/store/article/setPricesBySku.js +++ b/src/store/article/setPricesBySku.js @@ -42,6 +42,17 @@ function normalizePrices(prices) { return normalized; } +/** + * Replaces the price list of an article by its SKU. + * + * @param {object} pool - The mssql connection pool. + * @returns {Function} An async function that sets article prices. + * + * @example + * const fn = setPricesBySku(pool); + * const article = await fn(42, 'SKU-1', [{ price: 1.5, tax: 19, minmultiplier: 1 }]); + * // => { id, sku, name, ... } + */ export default function setPricesBySku(pool) { const resolve = resolveArticleBySku(pool); const ensureTax = taxEnsure(pool); diff --git a/src/store/article/setWeightBySku.js b/src/store/article/setWeightBySku.js index 7810b58..349c3fe 100644 --- a/src/store/article/setWeightBySku.js +++ b/src/store/article/setWeightBySku.js @@ -2,6 +2,17 @@ import { UPDATE_WEIGHT } from '../../sql/article.js'; import queryBySku from './queryBySku.js'; import resolveArticleBySku from './resolveArticleBySku.js'; +/** + * Sets the weight of an article by its SKU. + * + * @param {object} pool - The mssql connection pool. + * @returns {Function} An async function that sets the article weight. + * + * @example + * const fn = setWeightBySku(pool); + * const article = await fn(42, 'SKU-1', 1.5); + * // => { id, sku, name, ... } + */ export default function setWeightBySku(pool) { const resolve = resolveArticleBySku(pool); const load = queryBySku(pool); diff --git a/src/store/article/updateBySku.js b/src/store/article/updateBySku.js index 63f300d..dd44e21 100644 --- a/src/store/article/updateBySku.js +++ b/src/store/article/updateBySku.js @@ -20,6 +20,17 @@ function formatUnitLabel(amount, symbol) { return `${Number(amount)}${sym}`; } +/** + * Updates an article's name and/or unit (SI and amount), recording history. + * + * @param {object} pool - The mssql connection pool. + * @returns {Function} An async function that updates an article by SKU. + * + * @example + * const fn = updateBySku(pool); + * const article = await fn(42, 'SKU-1', { name: 'Cola 1L', unitSi: 'l', unitamount: 1 }); + * // => { id, sku, name, ... } + */ export default function updateBySku(pool) { const resolve = resolveArticleBySku(pool); const load = queryBySku(pool); diff --git a/src/store/brand/delete.js b/src/store/brand/delete.js index a3bcc06..0b5ea41 100644 --- a/src/store/brand/delete.js +++ b/src/store/brand/delete.js @@ -1,6 +1,16 @@ import { DELETE_BY_COMPANY_AND_ID } from '../../sql/brand.js'; import resolveCompanyAccess from '../companyuser/resolveCompanyAccess.js'; +/** + * Deletes a brand for a company by its id. + * + * @param {object} pool - The mssql connection pool. + * @returns {Function} An async function that deletes a brand. + * + * @example + * const fn = del(pool); + * await fn(42, 1, 3); + */ export default function del(pool) { const access = resolveCompanyAccess(pool); diff --git a/src/store/brand/list.js b/src/store/brand/list.js index 97c7d08..18f225a 100644 --- a/src/store/brand/list.js +++ b/src/store/brand/list.js @@ -1,6 +1,17 @@ import { LIST_BY_COMPANY } from '../../sql/brand.js'; import resolveCompanyAccess from '../companyuser/resolveCompanyAccess.js'; +/** + * Lists the brands of a company. + * + * @param {object} pool - The mssql connection pool. + * @returns {Function} An async function that lists brands. + * + * @example + * const fn = list(pool); + * const brands = await fn(42, 1); + * // => [{ id, name, gsprpinfo }] + */ export default function list(pool) { const access = resolveCompanyAccess(pool); diff --git a/src/store/brand/upsert.js b/src/store/brand/upsert.js index 609dccd..1e9753b 100644 --- a/src/store/brand/upsert.js +++ b/src/store/brand/upsert.js @@ -5,6 +5,17 @@ import { } from '../../sql/brand.js'; import resolveCompanyAccess from '../companyuser/resolveCompanyAccess.js'; +/** + * Creates or updates a brand for a company, keyed by name. + * + * @param {object} pool - The mssql connection pool. + * @returns {Function} An async function that upserts a brand. + * + * @example + * const fn = upsert(pool); + * const brand = await fn(42, 1, { name: 'Coca-Cola', gsprpinfo: 'x' }); + * // => { id, name, gsprpinfo } + */ export default function upsert(pool) { const access = resolveCompanyAccess(pool); diff --git a/src/store/category/addImage.js b/src/store/category/addImage.js index 8f0aa5c..b6d13ac 100644 --- a/src/store/category/addImage.js +++ b/src/store/category/addImage.js @@ -5,6 +5,17 @@ import newFullHash from '../../util/newFullHash.js'; import request from '../request.js'; import resolveCategoryAccess from './resolveCategoryAccess.js'; +/** + * Adds an image to a category, processing it into AVIF full and thumb variants. + * + * @param {object} pool - The mssql connection pool. + * @returns {Function} An async function that adds a category image. + * + * @example + * const fn = addImage(pool); + * const result = await fn(42, 5, imageBuffer); + * // => { id, fullHash, thumbW, thumbH, thumbHash } + */ export default function addImage(pool) { const access = resolveCategoryAccess(pool); diff --git a/src/store/category/createUnderParent.js b/src/store/category/createUnderParent.js index 027b860..5247439 100644 --- a/src/store/category/createUnderParent.js +++ b/src/store/category/createUnderParent.js @@ -7,6 +7,17 @@ import resolveCategoryAccess from './resolveCategoryAccess.js'; import request from '../request.js'; import slugify from '../slugify.js'; +/** + * Creates a new category under a given parent category. + * + * @param {object} pool - The mssql connection pool. + * @returns {Function} An async function that creates a category. + * + * @example + * const fn = createUnderParent(pool); + * const category = await fn({ googleAuthId: 42, parentId: 5, name: 'Drinks' }); + * // => { id, parentId, sort, name, slug } + */ export default function createUnderParent(pool) { const access = resolveCategoryAccess(pool); diff --git a/src/store/category/delete.js b/src/store/category/delete.js index 8f85947..0514148 100644 --- a/src/store/category/delete.js +++ b/src/store/category/delete.js @@ -1,6 +1,16 @@ import { DELETE } from '../../sql/category.js'; import resolveCategoryAccess from './resolveCategoryAccess.js'; +/** + * Deletes a category, refusing to delete the company's root category. + * + * @param {object} pool - The mssql connection pool. + * @returns {Function} An async function that deletes a category. + * + * @example + * const fn = del(pool); + * await fn({ googleAuthId: 42, id: 5 }); + */ export default function del(pool) { const access = resolveCategoryAccess(pool); diff --git a/src/store/category/deleteImage.js b/src/store/category/deleteImage.js index 3d053c6..90f346c 100644 --- a/src/store/category/deleteImage.js +++ b/src/store/category/deleteImage.js @@ -1,6 +1,17 @@ import { DELETE_BY_CATEGORY } from '../../sql/categorypic.js'; import resolveCategoryAccess from './resolveCategoryAccess.js'; +/** + * Deletes the image of a category. + * + * @param {object} pool - The mssql connection pool. + * @returns {Function} An async function that deletes a category image. + * + * @example + * const fn = deleteImage(pool); + * const result = await fn(42, 5); + * // => { id, thumbW: null, thumbH: null, thumbHash: null } + */ export default function deleteImage(pool) { const access = resolveCategoryAccess(pool); diff --git a/src/store/category/getCategoryArticles.js b/src/store/category/getCategoryArticles.js index 4c9ed6d..3009164 100644 --- a/src/store/category/getCategoryArticles.js +++ b/src/store/category/getCategoryArticles.js @@ -1,6 +1,17 @@ import resolveCategoryAccess from './resolveCategoryAccess.js'; import queryCategoryArticles from './queryCategoryArticles.js'; +/** + * Returns the articles belonging to a single category. + * + * @param {object} pool - The mssql connection pool. + * @returns {Function} An async function that fetches the articles of a category. + * + * @example + * const fn = getCategoryArticles(pool); + * const articles = await fn(42, 5); + * // => [{ id, sku, name, ... }] + */ export default function getCategoryArticles(pool) { const access = resolveCategoryAccess(pool); const articles = queryCategoryArticles(pool); diff --git a/src/store/category/getTreeForCompany.js b/src/store/category/getTreeForCompany.js index 662de9f..5d16ee3 100644 --- a/src/store/category/getTreeForCompany.js +++ b/src/store/category/getTreeForCompany.js @@ -3,6 +3,18 @@ import resolveCompanyAccess from '../companyuser/resolveCompanyAccess.js'; import queryCategoryArticles from './queryCategoryArticles.js'; import getCategoryPosterminalIds from '../posterminal/getCategoryPosterminalIds.js'; +/** + * Returns the full category tree for a company together with its articles and + * the posterminal ids assigned to each category. + * + * @param {object} pool - The mssql connection pool. + * @returns {Function} An async function that fetches the category tree. + * + * @example + * const fn = getTreeForCompany(pool); + * const tree = await fn(42, 1); + * // => { languageId, tree: [{ id, posterminalIds, ... }], articles: [...] } + */ export default function getTreeForCompany(pool) { const access = resolveCompanyAccess(pool); const articles = queryCategoryArticles(pool); diff --git a/src/store/category/move.js b/src/store/category/move.js index 94c9c6d..88242ae 100644 --- a/src/store/category/move.js +++ b/src/store/category/move.js @@ -6,6 +6,17 @@ import { import request from '../request.js'; import resolveCategoryAccess from './resolveCategoryAccess.js'; +/** + * Moves a category to a new parent, preventing cycles and cross-company moves. + * + * @param {object} pool - The mssql connection pool. + * @returns {Function} An async function that moves a category. + * + * @example + * const fn = move(pool); + * const result = await fn({ googleAuthId: 42, id: 5, parentId: 9 }); + * // => { id, parentId, sort } + */ export default function move(pool) { const access = resolveCategoryAccess(pool); diff --git a/src/store/category/order.js b/src/store/category/order.js index ae1f1a9..376067f 100644 --- a/src/store/category/order.js +++ b/src/store/category/order.js @@ -5,6 +5,17 @@ import { import request from '../request.js'; import resolveCategoryAccess from './resolveCategoryAccess.js'; +/** + * Reorders the child categories of a given parent. + * + * @param {object} pool - The mssql connection pool. + * @returns {Function} An async function that reorders categories. + * + * @example + * const fn = order(pool); + * const result = await fn({ googleAuthId: 42, parentId: 5, categoryIds: [3, 1, 2] }); + * // => { categoryIds: [3, 1, 2] } + */ export default function order(pool) { const access = resolveCategoryAccess(pool); diff --git a/src/store/category/rename.js b/src/store/category/rename.js index a5b5f16..554ea21 100644 --- a/src/store/category/rename.js +++ b/src/store/category/rename.js @@ -2,6 +2,17 @@ import { UPDATE_BY_CATEGORY_AND_LANGUAGE } from '../../sql/categorytext.js'; import resolveCategoryAccess from './resolveCategoryAccess.js'; import slugify from '../slugify.js'; +/** + * Renames a category and updates its slug. + * + * @param {object} pool - The mssql connection pool. + * @returns {Function} An async function that renames a category. + * + * @example + * const fn = rename(pool); + * const result = await fn({ googleAuthId: 42, id: 5, name: 'Soft Drinks' }); + * // => { id, name, slug } + */ export default function rename(pool) { const access = resolveCategoryAccess(pool); diff --git a/src/store/company/create.js b/src/store/company/create.js index 5895d35..b3e9e53 100644 --- a/src/store/company/create.js +++ b/src/store/company/create.js @@ -11,6 +11,24 @@ 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); diff --git a/src/store/company/delete.js b/src/store/company/delete.js index 34e46f3..283f4ca 100644 --- a/src/store/company/delete.js +++ b/src/store/company/delete.js @@ -1,5 +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) { return async (companyId) => { await pool diff --git a/src/store/company/getById.js b/src/store/company/getById.js index 24e9821..04b35fb 100644 --- a/src/store/company/getById.js +++ b/src/store/company/getById.js @@ -1,6 +1,17 @@ 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) { return async (id, tx) => { const result = await request(pool, tx) diff --git a/src/store/company/getByName.js b/src/store/company/getByName.js index 8b6ae14..3197c7f 100644 --- a/src/store/company/getByName.js +++ b/src/store/company/getByName.js @@ -1,6 +1,17 @@ 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) { return async (name, tx) => { const result = await request(pool, tx) diff --git a/src/store/company/list.js b/src/store/company/list.js index e057f2a..7ef868b 100644 --- a/src/store/company/list.js +++ b/src/store/company/list.js @@ -1,5 +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) { return async (googleAuthId) => { const result = await pool diff --git a/src/store/company/update.js b/src/store/company/update.js index a710be7..5849590 100644 --- a/src/store/company/update.js +++ b/src/store/company/update.js @@ -5,6 +5,17 @@ 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); diff --git a/src/store/companysetting/delete.js b/src/store/companysetting/delete.js index 29b83ea..1d818ca 100644 --- a/src/store/companysetting/delete.js +++ b/src/store/companysetting/delete.js @@ -1,6 +1,16 @@ import { DELETE_BY_COMPANY_AND_KEY } from '../../sql/companysetting.js'; import resolveCompanyAccess from '../companyuser/resolveCompanyAccess.js'; +/** + * Deletes a company setting by key. + * + * @param {object} pool - The mssql connection pool. + * @returns {Function} An async function that deletes a company setting. + * + * @example + * const fn = del(pool); + * await fn(42, 1, 'theme'); + */ export default function del(pool) { const access = resolveCompanyAccess(pool); diff --git a/src/store/companysetting/get.js b/src/store/companysetting/get.js index fa5562c..346c707 100644 --- a/src/store/companysetting/get.js +++ b/src/store/companysetting/get.js @@ -2,6 +2,17 @@ import { GET_BY_COMPANY_AND_KEY } from '../../sql/companysetting.js'; import resolveCompanyAccess from '../companyuser/resolveCompanyAccess.js'; import shapeSetting from './shapeSetting.js'; +/** + * Returns a single company setting by key. + * + * @param {object} pool - The mssql connection pool. + * @returns {Function} An async function that fetches a company setting. + * + * @example + * const fn = get(pool); + * const setting = await fn(42, 1, 'theme'); + * // => { key, value, frontend } + */ export default function get(pool) { const access = resolveCompanyAccess(pool); diff --git a/src/store/companysetting/list.js b/src/store/companysetting/list.js index d25354b..5a1203c 100644 --- a/src/store/companysetting/list.js +++ b/src/store/companysetting/list.js @@ -5,6 +5,17 @@ import { import resolveCompanyAccess from '../companyuser/resolveCompanyAccess.js'; import shapeSetting from './shapeSetting.js'; +/** + * Lists the settings of a company, optionally only frontend-visible ones. + * + * @param {object} pool - The mssql connection pool. + * @returns {Function} An async function that lists company settings. + * + * @example + * const fn = list(pool); + * const settings = await fn(42, 1, { frontendOnly: true }); + * // => [{ key, value, frontend }] + */ export default function list(pool) { const access = resolveCompanyAccess(pool); diff --git a/src/store/companysetting/set.js b/src/store/companysetting/set.js index 945ad42..42798db 100644 --- a/src/store/companysetting/set.js +++ b/src/store/companysetting/set.js @@ -2,6 +2,17 @@ import { GET_BY_COMPANY_AND_KEY, UPSERT } from '../../sql/companysetting.js'; import resolveCompanyAccess from '../companyuser/resolveCompanyAccess.js'; import shapeSetting from './shapeSetting.js'; +/** + * Sets (upserts) a company setting by key. + * + * @param {object} pool - The mssql connection pool. + * @returns {Function} An async function that sets a company setting. + * + * @example + * const fn = set(pool); + * const setting = await fn(42, 1, { key: 'theme', value: 'dark', frontend: true }); + * // => { key, value, frontend } + */ export default function set(pool) { const access = resolveCompanyAccess(pool); diff --git a/src/store/companyuser/add.js b/src/store/companyuser/add.js index 13bd22b..085fb53 100644 --- a/src/store/companyuser/add.js +++ b/src/store/companyuser/add.js @@ -1,5 +1,16 @@ 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) { return async (companyId, googleAuthId) => { const result = await pool diff --git a/src/store/companyuser/delete.js b/src/store/companyuser/delete.js index 3fe631e..0d5f28f 100644 --- a/src/store/companyuser/delete.js +++ b/src/store/companyuser/delete.js @@ -1,5 +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) { return async (id) => { await pool diff --git a/src/store/companyuser/getByEmail.js b/src/store/companyuser/getByEmail.js index 07f09f3..cfcb311 100644 --- a/src/store/companyuser/getByEmail.js +++ b/src/store/companyuser/getByEmail.js @@ -1,5 +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) { return async (email) => { const result = await pool diff --git a/src/store/customergroup/create.js b/src/store/customergroup/create.js index b3335da..799f236 100644 --- a/src/store/customergroup/create.js +++ b/src/store/customergroup/create.js @@ -8,6 +8,17 @@ function shape(row) { return { id: row.id, name: row.name, sort: row.sort }; } +/** + * Creates a new customer group for a company. + * + * @param {object} pool - The mssql connection pool. + * @returns {Function} An async function that creates a customer group. + * + * @example + * const fn = create(pool); + * const group = await fn(42, 1, { name: 'Wholesale' }); + * // => { id, name, sort } + */ export default function create(pool) { const access = resolveCompanyAccess(pool); diff --git a/src/store/customergroup/delete.js b/src/store/customergroup/delete.js index 782d11a..83b9055 100644 --- a/src/store/customergroup/delete.js +++ b/src/store/customergroup/delete.js @@ -1,6 +1,16 @@ import { DELETE_BY_COMPANY_AND_ID } from '../../sql/customergroup.js'; import resolveCompanyAccess from '../companyuser/resolveCompanyAccess.js'; +/** + * Deletes a customer group for a company by its id. + * + * @param {object} pool - The mssql connection pool. + * @returns {Function} An async function that deletes a customer group. + * + * @example + * const fn = del(pool); + * await fn(42, 1, 5); + */ export default function del(pool) { const access = resolveCompanyAccess(pool); diff --git a/src/store/customergroup/list.js b/src/store/customergroup/list.js index 186f3a8..5fa574d 100644 --- a/src/store/customergroup/list.js +++ b/src/store/customergroup/list.js @@ -1,6 +1,17 @@ import { LIST_BY_COMPANY } from '../../sql/customergroup.js'; import resolveCompanyAccess from '../companyuser/resolveCompanyAccess.js'; +/** + * Lists the customer groups of a company. + * + * @param {object} pool - The mssql connection pool. + * @returns {Function} An async function that lists customer groups. + * + * @example + * const fn = list(pool); + * const groups = await fn(42, 1); + * // => [{ id, name, sort }] + */ export default function list(pool) { const access = resolveCompanyAccess(pool); diff --git a/src/store/customergroup/order.js b/src/store/customergroup/order.js index ef18020..8482e30 100644 --- a/src/store/customergroup/order.js +++ b/src/store/customergroup/order.js @@ -5,6 +5,17 @@ import { import request from '../request.js'; import resolveCompanyAccess from '../companyuser/resolveCompanyAccess.js'; +/** + * Reorders the customer groups of a company. + * + * @param {object} pool - The mssql connection pool. + * @returns {Function} An async function that reorders customer groups. + * + * @example + * const fn = order(pool); + * const result = await fn(42, 1, { customergroupIds: [3, 1, 2] }); + * // => { customergroupIds: [3, 1, 2] } + */ export default function order(pool) { const access = resolveCompanyAccess(pool); diff --git a/src/store/customergroup/update.js b/src/store/customergroup/update.js index 7fb86fe..6ed8076 100644 --- a/src/store/customergroup/update.js +++ b/src/store/customergroup/update.js @@ -8,6 +8,17 @@ function shape(row) { return { id: row.id, name: row.name, sort: row.sort }; } +/** + * Updates the name of a customer group for a company. + * + * @param {object} pool - The mssql connection pool. + * @returns {Function} An async function that updates a customer group. + * + * @example + * const fn = update(pool); + * const group = await fn(42, 1, 5, { name: 'Retail' }); + * // => { id, name, sort } + */ export default function update(pool) { const access = resolveCompanyAccess(pool); diff --git a/src/store/delivery/create.js b/src/store/delivery/create.js index 704b869..4e106c9 100644 --- a/src/store/delivery/create.js +++ b/src/store/delivery/create.js @@ -9,6 +9,17 @@ import { } from './helpers.js'; import { assertSupplier, insertLines } from './writeLines.js'; +/** + * Creates a new delivery for a company with its lines. + * + * @param {object} pool - The mssql connection pool. + * @returns {Function} An async function that creates a delivery. + * + * @example + * const fn = create(pool); + * const delivery = await fn(42, 1, { number: 'D-1', date: '2026-01-01', supplierId: 5, lines: [...] }); + * // => { id, number, type, entityId, date, lines: [...] } + */ export default function create(pool) { const access = resolveCompanyAccess(pool); const ensureTax = taxEnsure(pool); diff --git a/src/store/delivery/delete.js b/src/store/delivery/delete.js index eb900a9..65a87be 100644 --- a/src/store/delivery/delete.js +++ b/src/store/delivery/delete.js @@ -1,6 +1,16 @@ import { DELETE_MANIFEST, DELIVERY_TYPE } from '../../sql/delivery.js'; import resolveCompanyAccess from '../companyuser/resolveCompanyAccess.js'; +/** + * Deletes a delivery by its id within a company. + * + * @param {object} pool - The mssql connection pool. + * @returns {Function} An async function that deletes a delivery. + * + * @example + * const fn = del(pool); + * await fn(42, 1, 5); + */ export default function del(pool) { const access = resolveCompanyAccess(pool); diff --git a/src/store/delivery/getById.js b/src/store/delivery/getById.js index eb6daad..a3263c8 100644 --- a/src/store/delivery/getById.js +++ b/src/store/delivery/getById.js @@ -1,6 +1,17 @@ import resolveCompanyAccess from '../companyuser/resolveCompanyAccess.js'; import { loadDelivery } from './helpers.js'; +/** + * Returns a single delivery by its id within a company. + * + * @param {object} pool - The mssql connection pool. + * @returns {Function} An async function that fetches a delivery by id. + * + * @example + * const fn = getById(pool); + * const delivery = await fn(42, 1, 5); + * // => { id, number, type, entityId, date, lines: [...] } + */ export default function getById(pool) { const access = resolveCompanyAccess(pool); diff --git a/src/store/delivery/list.js b/src/store/delivery/list.js index b95a931..038060a 100644 --- a/src/store/delivery/list.js +++ b/src/store/delivery/list.js @@ -2,6 +2,17 @@ import { DELIVERY_TYPE, LIST_DELIVERIES } from '../../sql/delivery.js'; import resolveCompanyAccess from '../companyuser/resolveCompanyAccess.js'; import { shapeSummary } from './helpers.js'; +/** + * Lists the deliveries of a company. + * + * @param {object} pool - The mssql connection pool. + * @returns {Function} An async function that lists deliveries. + * + * @example + * const fn = list(pool); + * const deliveries = await fn(42, 1); + * // => [{ id, number, type, entityId, date }] + */ export default function list(pool) { const access = resolveCompanyAccess(pool); diff --git a/src/store/delivery/update.js b/src/store/delivery/update.js index ed55901..b8c3418 100644 --- a/src/store/delivery/update.js +++ b/src/store/delivery/update.js @@ -15,6 +15,17 @@ import { } from './helpers.js'; import { assertSupplier, insertLines } from './writeLines.js'; +/** + * Updates a delivery's header and/or lines. + * + * @param {object} pool - The mssql connection pool. + * @returns {Function} An async function that updates a delivery. + * + * @example + * const fn = update(pool); + * const delivery = await fn(42, 1, 5, { number: 'D-2', lines: [...] }); + * // => { id, number, type, entityId, date, lines: [...] } + */ export default function update(pool) { const access = resolveCompanyAccess(pool); const ensureTax = taxEnsure(pool); diff --git a/src/store/entity/create.js b/src/store/entity/create.js index 2b57ca0..e44954c 100644 --- a/src/store/entity/create.js +++ b/src/store/entity/create.js @@ -15,6 +15,17 @@ function shape(row) { }; } +/** + * Creates a new entity (customer) in a customer group, recording history. + * + * @param {object} pool - The mssql connection pool. + * @returns {Function} An async function that creates an entity. + * + * @example + * const fn = create(pool); + * const entity = await fn(42, 1, { customergroupId: 5, name: 'Doe', firstName: 'John' }); + * // => { id, customergroupId, firstName, name, createdAt, updatedAt } + */ export default function create(pool) { const access = resolveCompanyAccess(pool); const groupAccess = resolveCustomerGroupAccess(pool); diff --git a/src/store/entity/delete.js b/src/store/entity/delete.js index 025f6d6..e32fd6d 100644 --- a/src/store/entity/delete.js +++ b/src/store/entity/delete.js @@ -1,6 +1,16 @@ import { DELETE_BY_COMPANY_AND_ID } from '../../sql/entity.js'; import resolveCompanyAccess from '../companyuser/resolveCompanyAccess.js'; +/** + * Deletes an entity by its id within a company. + * + * @param {object} pool - The mssql connection pool. + * @returns {Function} An async function that deletes an entity. + * + * @example + * const fn = del(pool); + * await fn(42, 1, 5); + */ export default function del(pool) { const access = resolveCompanyAccess(pool); diff --git a/src/store/entity/getById.js b/src/store/entity/getById.js index c75a864..a4e37ab 100644 --- a/src/store/entity/getById.js +++ b/src/store/entity/getById.js @@ -12,6 +12,17 @@ function shape(row) { }; } +/** + * Returns a single entity by its id within a company. + * + * @param {object} pool - The mssql connection pool. + * @returns {Function} An async function that fetches an entity by id. + * + * @example + * const fn = getById(pool); + * const entity = await fn(42, 1, 5); + * // => { id, customergroupId, firstName, name, createdAt, updatedAt } + */ export default function getById(pool) { const access = resolveCompanyAccess(pool); diff --git a/src/store/entity/list.js b/src/store/entity/list.js index 34a1d59..86de138 100644 --- a/src/store/entity/list.js +++ b/src/store/entity/list.js @@ -19,6 +19,18 @@ function shape(row) { }; } +/** + * Lists the entities (customers) of a company, optionally filtered by customer + * group or restricted to the 'customer' role. + * + * @param {object} pool - The mssql connection pool. + * @returns {Function} An async function that lists entities. + * + * @example + * const fn = list(pool); + * const entities = await fn(42, 1, { customergroupId: 5 }); + * // => [{ id, customergroupId, firstName, name, createdAt, updatedAt }] + */ export default function list(pool) { const access = resolveCompanyAccess(pool); const groupAccess = resolveCustomerGroupAccess(pool); diff --git a/src/store/entity/update.js b/src/store/entity/update.js index 8b9b893..5744f06 100644 --- a/src/store/entity/update.js +++ b/src/store/entity/update.js @@ -14,6 +14,17 @@ function shape(row) { }; } +/** + * Updates the name and/or first name of an entity, recording history. + * + * @param {object} pool - The mssql connection pool. + * @returns {Function} An async function that updates an entity. + * + * @example + * const fn = update(pool); + * const entity = await fn(42, 1, 5, { name: 'Doe', firstName: 'Jane' }); + * // => { id, customergroupId, firstName, name, createdAt, updatedAt } + */ export default function update(pool) { const access = resolveCompanyAccess(pool); diff --git a/src/store/entityaddress/create.js b/src/store/entityaddress/create.js index 1475c94..4f7d510 100644 --- a/src/store/entityaddress/create.js +++ b/src/store/entityaddress/create.js @@ -24,6 +24,17 @@ function optionalString(value) { return s || null; } +/** + * Creates a new address for an entity. + * + * @param {object} pool - The mssql connection pool. + * @returns {Function} An async function that creates an entity address. + * + * @example + * const fn = create(pool); + * const address = await fn(42, 1, 5, { addressType: 'billing', street: 'Main St', city: 'Berlin' }); + * // => { id, entityId, firstName, name, street, streetNumber, zip, city, county, addressType, sort } + */ export default function create(pool) { const access = resolveCompanyAccess(pool); const entityAccess = resolveEntityAccess(pool); diff --git a/src/store/entityaddress/delete.js b/src/store/entityaddress/delete.js index 34038eb..0446de8 100644 --- a/src/store/entityaddress/delete.js +++ b/src/store/entityaddress/delete.js @@ -2,6 +2,16 @@ import { DELETE_BY_ENTITY_AND_ID } from '../../sql/entityaddress.js'; import resolveCompanyAccess from '../companyuser/resolveCompanyAccess.js'; import resolveEntityAccess from '../entity/resolveEntityAccess.js'; +/** + * Deletes an address of an entity. + * + * @param {object} pool - The mssql connection pool. + * @returns {Function} An async function that deletes an entity address. + * + * @example + * const fn = del(pool); + * await fn(42, 1, 5, 9); + */ export default function del(pool) { const access = resolveCompanyAccess(pool); const entityAccess = resolveEntityAccess(pool); diff --git a/src/store/entityaddress/list.js b/src/store/entityaddress/list.js index bec8d90..e6f433c 100644 --- a/src/store/entityaddress/list.js +++ b/src/store/entityaddress/list.js @@ -18,6 +18,17 @@ function shape(row) { }; } +/** + * Lists the addresses of an entity. + * + * @param {object} pool - The mssql connection pool. + * @returns {Function} An async function that lists entity addresses. + * + * @example + * const fn = list(pool); + * const addresses = await fn(42, 1, 5); + * // => [{ id, entityId, firstName, name, street, streetNumber, zip, city, county, addressType, sort }] + */ export default function list(pool) { const access = resolveCompanyAccess(pool); const entityAccess = resolveEntityAccess(pool); diff --git a/src/store/entityaddress/update.js b/src/store/entityaddress/update.js index f0d3c0c..68e22c7 100644 --- a/src/store/entityaddress/update.js +++ b/src/store/entityaddress/update.js @@ -24,6 +24,17 @@ function optionalString(value) { return s || null; } +/** + * Updates an address of an entity. + * + * @param {object} pool - The mssql connection pool. + * @returns {Function} An async function that updates an entity address. + * + * @example + * const fn = update(pool); + * const address = await fn(42, 1, 5, 9, { city: 'Hamburg' }); + * // => { id, entityId, firstName, name, street, streetNumber, zip, city, county, addressType, sort } + */ export default function update(pool) { const access = resolveCompanyAccess(pool); const entityAccess = resolveEntityAccess(pool); diff --git a/src/store/entitycontact/create.js b/src/store/entitycontact/create.js index 370fcb3..dadcbe0 100644 --- a/src/store/entitycontact/create.js +++ b/src/store/entitycontact/create.js @@ -12,6 +12,17 @@ function shape(row) { }; } +/** + * Creates a new contact for an entity. + * + * @param {object} pool - The mssql connection pool. + * @returns {Function} An async function that creates an entity contact. + * + * @example + * const fn = create(pool); + * const contact = await fn(42, 1, 5, { contactType: 'email', contact: 'a@b.c' }); + * // => { id, entityId, contactType, contact, sort } + */ export default function create(pool) { const access = resolveCompanyAccess(pool); const entityAccess = resolveEntityAccess(pool); diff --git a/src/store/entitycontact/delete.js b/src/store/entitycontact/delete.js index 62def26..3d435c8 100644 --- a/src/store/entitycontact/delete.js +++ b/src/store/entitycontact/delete.js @@ -2,6 +2,16 @@ import { DELETE_BY_ENTITY_AND_ID } from '../../sql/entitycontact.js'; import resolveCompanyAccess from '../companyuser/resolveCompanyAccess.js'; import resolveEntityAccess from '../entity/resolveEntityAccess.js'; +/** + * Deletes a contact of an entity. + * + * @param {object} pool - The mssql connection pool. + * @returns {Function} An async function that deletes an entity contact. + * + * @example + * const fn = del(pool); + * await fn(42, 1, 5, 9); + */ export default function del(pool) { const access = resolveCompanyAccess(pool); const entityAccess = resolveEntityAccess(pool); diff --git a/src/store/entitycontact/list.js b/src/store/entitycontact/list.js index 1fc285a..a43dfae 100644 --- a/src/store/entitycontact/list.js +++ b/src/store/entitycontact/list.js @@ -12,6 +12,17 @@ function shape(row) { }; } +/** + * Lists the contacts of an entity. + * + * @param {object} pool - The mssql connection pool. + * @returns {Function} An async function that lists entity contacts. + * + * @example + * const fn = list(pool); + * const contacts = await fn(42, 1, 5); + * // => [{ id, entityId, contactType, contact, sort }] + */ export default function list(pool) { const access = resolveCompanyAccess(pool); const entityAccess = resolveEntityAccess(pool); diff --git a/src/store/entitycontact/update.js b/src/store/entitycontact/update.js index f227e93..cc64f36 100644 --- a/src/store/entitycontact/update.js +++ b/src/store/entitycontact/update.js @@ -12,6 +12,17 @@ function shape(row) { }; } +/** + * Updates a contact of an entity. + * + * @param {object} pool - The mssql connection pool. + * @returns {Function} An async function that updates an entity contact. + * + * @example + * const fn = update(pool); + * const contact = await fn(42, 1, 5, 9, { contact: 'b@c.d' }); + * // => { id, entityId, contactType, contact, sort } + */ export default function update(pool) { const access = resolveCompanyAccess(pool); const entityAccess = resolveEntityAccess(pool); diff --git a/src/store/google_auth/add.js b/src/store/google_auth/add.js index 81c0232..94e2c5f 100644 --- a/src/store/google_auth/add.js +++ b/src/store/google_auth/add.js @@ -1,5 +1,16 @@ import { ADD } from '../../sql/google_auth.js'; +/** + * Adds a new allowed Google auth email. + * + * @param {object} pool - The mssql connection pool. + * @returns {Function} An async function that adds an allowed email. + * + * @example + * const fn = add(pool); + * const id = await fn('user@example.com'); + * // => 1 + */ export default function add(pool) { return async (email) => { const result = await pool diff --git a/src/store/google_auth/getByEmail.js b/src/store/google_auth/getByEmail.js index c47eb69..40f2c24 100644 --- a/src/store/google_auth/getByEmail.js +++ b/src/store/google_auth/getByEmail.js @@ -1,5 +1,16 @@ import { GET_BY_EMAIL } from '../../sql/google_auth.js'; +/** + * Returns a Google auth row by email. + * + * @param {object} pool - The mssql connection pool. + * @returns {Function} An async function that fetches a Google auth row by email. + * + * @example + * const fn = getByEmail(pool); + * const auth = await fn('user@example.com'); + * // => { id, email, ... } + */ export default function getByEmail(pool) { return async (email) => { const result = await pool diff --git a/src/store/google_auth/getById.js b/src/store/google_auth/getById.js index 866e768..a079b79 100644 --- a/src/store/google_auth/getById.js +++ b/src/store/google_auth/getById.js @@ -1,5 +1,16 @@ import { GET_BY_ID } from '../../sql/google_auth.js'; +/** + * Returns a Google auth row by its id. + * + * @param {object} pool - The mssql connection pool. + * @returns {Function} An async function that fetches a Google auth row by id. + * + * @example + * const fn = getById(pool); + * const auth = await fn(42); + * // => { id, email, ... } + */ export default function getById(pool) { return async (googleAuthId) => { const result = await pool diff --git a/src/store/google_auth/listAllowedEmails.js b/src/store/google_auth/listAllowedEmails.js index 34bd0fe..7cddf8d 100644 --- a/src/store/google_auth/listAllowedEmails.js +++ b/src/store/google_auth/listAllowedEmails.js @@ -1,5 +1,16 @@ import { LIST_ALLOWED_EMAILS } from '../../sql/google_auth.js'; +/** + * Lists all allowed Google auth emails. + * + * @param {object} pool - The mssql connection pool. + * @returns {Function} An async function that lists allowed emails. + * + * @example + * const fn = listAllowedEmails(pool); + * const emails = await fn(); + * // => [{ id, email }] + */ export default function listAllowedEmails(pool) { return async () => { const result = await pool.request().query(LIST_ALLOWED_EMAILS); diff --git a/src/store/google_auth/removeAllowedEmail.js b/src/store/google_auth/removeAllowedEmail.js index 76b04dd..5fe377a 100644 --- a/src/store/google_auth/removeAllowedEmail.js +++ b/src/store/google_auth/removeAllowedEmail.js @@ -1,5 +1,15 @@ import { REMOVE_ALLOWED_EMAIL } from '../../sql/google_auth.js'; +/** + * Removes an allowed Google auth email. + * + * @param {object} pool - The mssql connection pool. + * @returns {Function} An async function that removes an allowed email. + * + * @example + * const fn = removeAllowedEmail(pool); + * await fn('user@example.com'); + */ export default function removeAllowedEmail(pool) { return async (email) => { await pool diff --git a/src/store/google_auth/setProfile.js b/src/store/google_auth/setProfile.js index b058c09..cdc1259 100644 --- a/src/store/google_auth/setProfile.js +++ b/src/store/google_auth/setProfile.js @@ -1,5 +1,15 @@ import { SET_PROFILE } from '../../sql/google_auth.js'; +/** + * Updates the profile (picture, picture binary, sub) of a Google auth user. + * + * @param {object} pool - The mssql connection pool. + * @returns {Function} An async function that sets the user profile. + * + * @example + * const fn = setProfile(pool); + * await fn(42, { picture: 'url', pictureBinary: buffer, sub: 'sub' }); + */ export default function setProfile(pool) { return async ( googleAuthId, diff --git a/src/store/google_auth/setSelectedCompany.js b/src/store/google_auth/setSelectedCompany.js index 203adf2..d571750 100644 --- a/src/store/google_auth/setSelectedCompany.js +++ b/src/store/google_auth/setSelectedCompany.js @@ -1,5 +1,15 @@ import { SET_SELECTED_COMPANY } from '../../sql/google_auth.js'; +/** + * Sets the currently selected company for a Google auth user. + * + * @param {object} pool - The mssql connection pool. + * @returns {Function} An async function that sets the selected company. + * + * @example + * const fn = setSelectedCompany(pool); + * await fn(42, 1); + */ export default function setSelectedCompany(pool) { return async (googleAuthId, companyId) => { await pool diff --git a/src/store/initialize.js b/src/store/initialize.js index 0bed354..835be2e 100644 --- a/src/store/initialize.js +++ b/src/store/initialize.js @@ -1,5 +1,15 @@ import { SCHEMA_SCRIPTS } from '../schema.js'; +/** + * Initializes the database schema by running all schema scripts. + * + * @param {object} pool - The mssql connection pool. + * @returns {Function} An async function that initializes the schema. + * + * @example + * const fn = initialize(pool); + * await fn(); + */ export default function initialize(pool) { return async () => { for (const script of SCHEMA_SCRIPTS) { diff --git a/src/store/lang/create.js b/src/store/lang/create.js index a60f7ad..9e5682b 100644 --- a/src/store/lang/create.js +++ b/src/store/lang/create.js @@ -1,6 +1,17 @@ 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) { return async (iso639, tx) => { const result = await request(pool, tx) diff --git a/src/store/lang/delete.js b/src/store/lang/delete.js index 5420238..14fe0e9 100644 --- a/src/store/lang/delete.js +++ b/src/store/lang/delete.js @@ -1,5 +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) { return async (id) => { await pool diff --git a/src/store/lang/ensure.js b/src/store/lang/ensure.js index f087ffc..36db379 100644 --- a/src/store/lang/ensure.js +++ b/src/store/lang/ensure.js @@ -1,6 +1,17 @@ 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); diff --git a/src/store/lang/getByIso639.js b/src/store/lang/getByIso639.js index 9412178..4a72a72 100644 --- a/src/store/lang/getByIso639.js +++ b/src/store/lang/getByIso639.js @@ -1,6 +1,17 @@ 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) { return async (iso639, tx) => { const result = await request(pool, tx) diff --git a/src/store/lang/list.js b/src/store/lang/list.js index fc259f3..ae4ecdd 100644 --- a/src/store/lang/list.js +++ b/src/store/lang/list.js @@ -1,5 +1,16 @@ 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) { return async () => { const result = await pool.request().query(LIST); diff --git a/src/store/manifestDoc/createStore.js b/src/store/manifestDoc/createStore.js index 6adc9b3..5698e7b 100644 --- a/src/store/manifestDoc/createStore.js +++ b/src/store/manifestDoc/createStore.js @@ -184,6 +184,13 @@ export default function createManifestDocStore(pool, { type, label }) { const notFound = `${label} not found`; const invalid = `Invalid ${label.toLowerCase()}`; + /** + * Lists the quote/order documents of a company. + * + * @param {number} googleAuthId - The Google auth user id. + * @param {number} companyId - The company id. + * @returns {Promise>} The document summaries. + */ async function list(googleAuthId, companyId) { await access(googleAuthId, companyId); @@ -196,6 +203,14 @@ export default function createManifestDocStore(pool, { type, label }) { return result.recordset.map((row) => shapeSummary(type, row)); } + /** + * Returns a single quote/order document by its id within a company. + * + * @param {number} googleAuthId - The Google auth user id. + * @param {number} companyId - The company id. + * @param {number} id - The document id. + * @returns {Promise} The document with its lines, or null if not found. + */ async function getById(googleAuthId, companyId, id) { if (!Number.isFinite(id)) { throw new Error(notFound); @@ -210,6 +225,14 @@ export default function createManifestDocStore(pool, { type, label }) { return doc; } + /** + * Creates a new quote/order document with its lines. + * + * @param {number} googleAuthId - The Google auth user id. + * @param {number} companyId - The company id. + * @param {object} body - The document payload (`number`, `date`, `entityId`, `lines`). + * @returns {Promise} The created document with its lines. + */ async function create(googleAuthId, companyId, body = {}) { const number = body.number?.trim?.() ? body.number.trim() : null; const date = parseDate(body.date); @@ -261,6 +284,15 @@ export default function createManifestDocStore(pool, { type, label }) { } } + /** + * Updates a quote/order document's header and/or lines. + * + * @param {number} googleAuthId - The Google auth user id. + * @param {number} companyId - The company id. + * @param {number} id - The document id. + * @param {object} patch - The fields to update (`number`, `date`, `entityId`, `lines`). + * @returns {Promise} The updated document with its lines. + */ async function update(googleAuthId, companyId, id, patch = {}) { if (!Number.isFinite(id)) { throw new Error(notFound); @@ -360,6 +392,14 @@ export default function createManifestDocStore(pool, { type, label }) { } } + /** + * Deletes a quote/order document by its id within a company. + * + * @param {number} googleAuthId - The Google auth user id. + * @param {number} companyId - The company id. + * @param {number} id - The document id. + * @returns {Promise} + */ async function del(googleAuthId, companyId, id) { if (!Number.isFinite(id)) { throw new Error(notFound); diff --git a/src/store/order/index.js b/src/store/order/index.js index e8c5582..c98d075 100644 --- a/src/store/order/index.js +++ b/src/store/order/index.js @@ -1,6 +1,18 @@ import { ORDER_TYPE } from '../../sql/manifestDoc.js'; import createManifestDocStore from '../manifestDoc/createStore.js'; +/** + * Creates an order store (list, getById, create, update, delete) backed by the + * manifest / manifestarticle tables. + * + * @param {object} pool - The mssql connection pool. + * @returns {object} An object with `list`, `getById`, `create`, `update` and `delete` functions. + * + * @example + * const store = createOrderStore(pool); + * const orders = await store.list(42, 1); + * // => [{ id, number, type, entityId, date }] + */ export default function createOrderStore(pool) { return createManifestDocStore(pool, { type: ORDER_TYPE, label: 'Order' }); } diff --git a/src/store/pic/getImageByHash.js b/src/store/pic/getImageByHash.js index da4afe4..7ab2d12 100644 --- a/src/store/pic/getImageByHash.js +++ b/src/store/pic/getImageByHash.js @@ -1,6 +1,17 @@ import { GET_FULL_BY_HASH } from '../../sql/pic.js'; import resolvePicAccess from './resolvePicAccess.js'; +/** + * Returns the full-size image (AVIF) for a given hash. + * + * @param {object} pool - The mssql connection pool. + * @returns {Function} An async function that fetches a full image by hash. + * + * @example + * const fn = getImageByHash(pool); + * const image = await fn(42, 'abc123'); + * // => { buffer, w, h, size, contentType: 'image/avif' } + */ export default function getImageByHash(pool) { const authorize = resolvePicAccess(pool); diff --git a/src/store/pic/getThumbByHash.js b/src/store/pic/getThumbByHash.js index 8e50e1c..7c12ac5 100644 --- a/src/store/pic/getThumbByHash.js +++ b/src/store/pic/getThumbByHash.js @@ -1,6 +1,17 @@ import { GET_THUMB_BY_HASH } from '../../sql/pic.js'; import resolvePicAccess from './resolvePicAccess.js'; +/** + * Returns the thumbnail image (AVIF) for a given hash. + * + * @param {object} pool - The mssql connection pool. + * @returns {Function} An async function that fetches a thumbnail by hash. + * + * @example + * const fn = getThumbByHash(pool); + * const thumb = await fn(42, 'abc123'); + * // => { buffer, w, h, contentType: 'image/avif' } + */ export default function getThumbByHash(pool) { const authorize = resolvePicAccess(pool); diff --git a/src/store/posterminal/delete.js b/src/store/posterminal/delete.js index 7fb538a..c610905 100644 --- a/src/store/posterminal/delete.js +++ b/src/store/posterminal/delete.js @@ -1,6 +1,16 @@ import { DELETE_BY_COMPANY_AND_ID } from '../../sql/posterminal.js'; import resolveCompanyAccess from '../companyuser/resolveCompanyAccess.js'; +/** + * Deletes a posterminal by its id within a company. + * + * @param {object} pool - The mssql connection pool. + * @returns {Function} An async function that deletes a posterminal. + * + * @example + * const fn = del(pool); + * await fn(42, 1, 5); + */ export default function del(pool) { const access = resolveCompanyAccess(pool); diff --git a/src/store/posterminal/getCategoryPosterminalIds.js b/src/store/posterminal/getCategoryPosterminalIds.js index 5e2d0b9..8ce5d1f 100644 --- a/src/store/posterminal/getCategoryPosterminalIds.js +++ b/src/store/posterminal/getCategoryPosterminalIds.js @@ -1,5 +1,17 @@ import { POSTERMINAL_IDS_BY_COMPANY } from '../../sql/posterminal.js'; +/** + * Returns a map of category id to the posterminal ids assigned to it for a + * company. + * + * @param {object} pool - The mssql connection pool. + * @returns {Function} An async function that builds the category→posterminal map. + * + * @example + * const fn = getCategoryPosterminalIds(pool); + * const map = await fn(1); + * // => { 5: [1, 2], 9: [1] } + */ export default function getCategoryPosterminalIds(pool) { return async (companyId) => { const result = await pool diff --git a/src/store/posterminal/list.js b/src/store/posterminal/list.js index 7d448e6..4ea3fc4 100644 --- a/src/store/posterminal/list.js +++ b/src/store/posterminal/list.js @@ -1,6 +1,17 @@ import { LIST_BY_COMPANY } from '../../sql/posterminal.js'; import resolveCompanyAccess from '../companyuser/resolveCompanyAccess.js'; +/** + * Lists the posterminals of a company. + * + * @param {object} pool - The mssql connection pool. + * @returns {Function} An async function that lists posterminals. + * + * @example + * const fn = list(pool); + * const terminals = await fn(42, 1); + * // => [{ id, name, token, pairingpin }] + */ export default function list(pool) { const access = resolveCompanyAccess(pool); diff --git a/src/store/posterminal/setOff.js b/src/store/posterminal/setOff.js index 5340e78..57ca497 100644 --- a/src/store/posterminal/setOff.js +++ b/src/store/posterminal/setOff.js @@ -1,6 +1,17 @@ import { GET_BY_ID, SET_OFF, LIST_CATEGORY_IDS } from '../../sql/posterminal.js'; import resolveCompanyAccess from '../companyuser/resolveCompanyAccess.js'; +/** + * Removes a category assignment from a posterminal (turns it off). + * + * @param {object} pool - The mssql connection pool. + * @returns {Function} An async function that removes a category from a posterminal. + * + * @example + * const fn = setOff(pool); + * const result = await fn(42, 1, 5, 9); + * // => { id, categoryIds: [...] } + */ export default function setOff(pool) { const access = resolveCompanyAccess(pool); diff --git a/src/store/posterminal/setOffAll.js b/src/store/posterminal/setOffAll.js index ec48b2e..bc1cda2 100644 --- a/src/store/posterminal/setOffAll.js +++ b/src/store/posterminal/setOffAll.js @@ -1,6 +1,17 @@ import { GET_BY_ID, SET_OFF_ALL, LIST_CATEGORY_IDS } from '../../sql/posterminal.js'; import resolveCompanyAccess from '../companyuser/resolveCompanyAccess.js'; +/** + * Removes all category assignments from a posterminal. + * + * @param {object} pool - The mssql connection pool. + * @returns {Function} An async function that clears all categories from a posterminal. + * + * @example + * const fn = setOffAll(pool); + * const result = await fn(42, 1, 5); + * // => { id, categoryIds: [] } + */ export default function setOffAll(pool) { const access = resolveCompanyAccess(pool); diff --git a/src/store/posterminal/setOn.js b/src/store/posterminal/setOn.js index 74931e2..dda0113 100644 --- a/src/store/posterminal/setOn.js +++ b/src/store/posterminal/setOn.js @@ -1,6 +1,17 @@ import { GET_BY_ID, SET_ON, LIST_CATEGORY_IDS } from '../../sql/posterminal.js'; import resolveCompanyAccess from '../companyuser/resolveCompanyAccess.js'; +/** + * Assigns a category to a posterminal (turns it on for that category). + * + * @param {object} pool - The mssql connection pool. + * @returns {Function} An async function that assigns a category to a posterminal. + * + * @example + * const fn = setOn(pool); + * const result = await fn(42, 1, 5, 9); + * // => { id, categoryIds: [9, ...] } + */ export default function setOn(pool) { const access = resolveCompanyAccess(pool); diff --git a/src/store/posterminal/setOnAll.js b/src/store/posterminal/setOnAll.js index 95409cd..bc34152 100644 --- a/src/store/posterminal/setOnAll.js +++ b/src/store/posterminal/setOnAll.js @@ -2,6 +2,17 @@ import { GET_BY_ID, SET_ON_ALL, LIST_CATEGORY_IDS } from '../../sql/posterminal. import resolveCompanyAccess from '../companyuser/resolveCompanyAccess.js'; import { GET_COMPANY_ROOT_CATEGORY } from '../../sql/company.js'; +/** + * Assigns all categories of a company to a posterminal. + * + * @param {object} pool - The mssql connection pool. + * @returns {Function} An async function that assigns all categories to a posterminal. + * + * @example + * const fn = setOnAll(pool); + * const result = await fn(42, 1, 5); + * // => { id, categoryIds: [...] } + */ export default function setOnAll(pool) { const access = resolveCompanyAccess(pool); diff --git a/src/store/posterminal/upsert.js b/src/store/posterminal/upsert.js index 3e0bf6a..7d7a617 100644 --- a/src/store/posterminal/upsert.js +++ b/src/store/posterminal/upsert.js @@ -1,6 +1,17 @@ import { GET_BY_ID, CREATE, UPDATE } from '../../sql/posterminal.js'; import resolveCompanyAccess from '../companyuser/resolveCompanyAccess.js'; +/** + * Creates or updates a posterminal for a company. + * + * @param {object} pool - The mssql connection pool. + * @returns {Function} An async function that upserts a posterminal. + * + * @example + * const fn = upsert(pool); + * const terminal = await fn(42, 1, { name: 'Kasse 1', pairingpin: '1234', token: 'abc' }); + * // => { id, name, token, pairingpin } + */ export default function upsert(pool) { const access = resolveCompanyAccess(pool); diff --git a/src/store/purge.js b/src/store/purge.js index b4bdafc..907b728 100644 --- a/src/store/purge.js +++ b/src/store/purge.js @@ -1,5 +1,15 @@ import { buildPurgeSql } from '../sql/purge.js'; +/** + * Purges (wipes) all data from the database. + * + * @param {object} pool - The mssql connection pool. + * @returns {Function} An async function that purges the database. + * + * @example + * const fn = purge(pool); + * await fn(); + */ export default function purge(pool) { return async () => { await pool.request().query(buildPurgeSql()); diff --git a/src/store/quote/index.js b/src/store/quote/index.js index 6cee215..4a88521 100644 --- a/src/store/quote/index.js +++ b/src/store/quote/index.js @@ -1,6 +1,18 @@ import { QUOTE_TYPE } from '../../sql/manifestDoc.js'; import createManifestDocStore from '../manifestDoc/createStore.js'; +/** + * Creates a quote store (list, getById, create, update, delete) backed by the + * manifest / manifestarticle tables. + * + * @param {object} pool - The mssql connection pool. + * @returns {object} An object with `list`, `getById`, `create`, `update` and `delete` functions. + * + * @example + * const store = createQuoteStore(pool); + * const quotes = await store.list(42, 1); + * // => [{ id, number, type, entityId, date }] + */ export default function createQuoteStore(pool) { return createManifestDocStore(pool, { type: QUOTE_TYPE, label: 'Quote' }); } diff --git a/src/store/supplier/create.js b/src/store/supplier/create.js index 959f2bf..24d29ae 100644 --- a/src/store/supplier/create.js +++ b/src/store/supplier/create.js @@ -4,6 +4,17 @@ import request from '../request.js'; import resolveCompanyAccess from '../companyuser/resolveCompanyAccess.js'; import ensureLieferantenGroup from './ensureLieferantenGroup.js'; +/** + * Creates a new supplier for a company, recording history. + * + * @param {object} pool - The mssql connection pool. + * @returns {Function} An async function that creates a supplier. + * + * @example + * const fn = create(pool); + * const supplier = await fn(42, 1, { name: 'Acme Supplies' }); + * // => { id, name, createdAt, updatedAt } + */ export default function create(pool) { const access = resolveCompanyAccess(pool); diff --git a/src/store/supplier/delete.js b/src/store/supplier/delete.js index d09a58c..0566bbd 100644 --- a/src/store/supplier/delete.js +++ b/src/store/supplier/delete.js @@ -1,6 +1,16 @@ import { DELETE_BY_ID, SUPPLIER_GROUP_NAME } from '../../sql/entity.js'; import resolveCompanyAccess from '../companyuser/resolveCompanyAccess.js'; +/** + * Deletes a supplier by its id within a company. + * + * @param {object} pool - The mssql connection pool. + * @returns {Function} An async function that deletes a supplier. + * + * @example + * const fn = del(pool); + * await fn(42, 1, 5); + */ export default function del(pool) { const access = resolveCompanyAccess(pool); diff --git a/src/store/supplier/list.js b/src/store/supplier/list.js index 0481bbf..b686bbc 100644 --- a/src/store/supplier/list.js +++ b/src/store/supplier/list.js @@ -1,6 +1,17 @@ import { LIST_SUPPLIERS_BY_COMPANY, SUPPLIER_GROUP_NAME } from '../../sql/entity.js'; import resolveCompanyAccess from '../companyuser/resolveCompanyAccess.js'; +/** + * Lists the suppliers of a company. + * + * @param {object} pool - The mssql connection pool. + * @returns {Function} An async function that lists suppliers. + * + * @example + * const fn = list(pool); + * const suppliers = await fn(42, 1); + * // => [{ id, name, createdAt, updatedAt }] + */ export default function list(pool) { const access = resolveCompanyAccess(pool); diff --git a/src/store/supplier/update.js b/src/store/supplier/update.js index eaddc83..f2ed0cb 100644 --- a/src/store/supplier/update.js +++ b/src/store/supplier/update.js @@ -17,6 +17,17 @@ function shape(row) { }; } +/** + * Updates the name of a supplier, recording history. + * + * @param {object} pool - The mssql connection pool. + * @returns {Function} An async function that updates a supplier. + * + * @example + * const fn = update(pool); + * const supplier = await fn(42, 1, 5, { name: 'Acme GmbH' }); + * // => { id, name, createdAt, updatedAt } + */ export default function update(pool) { const access = resolveCompanyAccess(pool); diff --git a/src/store/tax/create.js b/src/store/tax/create.js index ed0a916..34320c7 100644 --- a/src/store/tax/create.js +++ b/src/store/tax/create.js @@ -1,6 +1,17 @@ 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) { return async (rate, tx) => { const result = await request(pool, tx) diff --git a/src/store/tax/ensure.js b/src/store/tax/ensure.js index 3e895fb..37f5494 100644 --- a/src/store/tax/ensure.js +++ b/src/store/tax/ensure.js @@ -1,6 +1,17 @@ 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); diff --git a/src/store/tax/getByRate.js b/src/store/tax/getByRate.js index fe565a0..f1f5f2a 100644 --- a/src/store/tax/getByRate.js +++ b/src/store/tax/getByRate.js @@ -1,6 +1,17 @@ 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) { return async (rate, tx) => { const result = await request(pool, tx) diff --git a/src/store/tax/list.js b/src/store/tax/list.js index 52b9806..23187f2 100644 --- a/src/store/tax/list.js +++ b/src/store/tax/list.js @@ -1,5 +1,16 @@ 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) { return async () => { const result = await pool.request().query(LIST); diff --git a/src/store/unit/delete.js b/src/store/unit/delete.js index 0489730..89383dd 100644 --- a/src/store/unit/delete.js +++ b/src/store/unit/delete.js @@ -1,6 +1,16 @@ import { DELETE_BY_COMPANY_AND_SI } from '../../sql/unit.js'; import resolveCompanyAccess from '../companyuser/resolveCompanyAccess.js'; +/** + * Deletes a unit for a company by its SI code. + * + * @param {object} pool - The mssql connection pool. + * @returns {Function} An async function that deletes a unit. + * + * @example + * const fn = del(pool); + * await fn(42, 1, 'l'); + */ export default function del(pool) { const access = resolveCompanyAccess(pool); diff --git a/src/store/unit/list.js b/src/store/unit/list.js index 4f0f8dc..4613b04 100644 --- a/src/store/unit/list.js +++ b/src/store/unit/list.js @@ -2,6 +2,17 @@ import { LIST_BY_COMPANY } from '../../sql/unit.js'; import resolveCompanyAccess from '../companyuser/resolveCompanyAccess.js'; import shapeUnit from './shapeUnit.js'; +/** + * Lists the units available for a company. + * + * @param {object} pool - The mssql connection pool. + * @returns {Function} An async function that lists units. + * + * @example + * const fn = list(pool); + * const units = await fn(42, 1); + * // => [{ id, si, basesi, basesifactor, symbol, name }] + */ export default function list(pool) { const access = resolveCompanyAccess(pool); diff --git a/src/store/unit/upsert.js b/src/store/unit/upsert.js index 5ec0c6d..cf0a93a 100644 --- a/src/store/unit/upsert.js +++ b/src/store/unit/upsert.js @@ -30,6 +30,17 @@ function validateUnit({ si, basesi, basesifactor, symbol, name }) { }; } +/** + * Creates or updates a unit for a company, keyed by its SI code. + * + * @param {object} pool - The mssql connection pool. + * @returns {Function} An async function that upserts a unit. + * + * @example + * const fn = upsert(pool); + * const unit = await fn(42, 1, { si: 'l', basesi: 'm3', basesifactor: 0.001, symbol: 'L', name: 'Liter' }); + * // => { id, si, basesi, basesifactor, symbol, name } + */ export default function upsert(pool) { const access = resolveCompanyAccess(pool);