docs: add JSDoc headers to all externally exported store functions
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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<Array<object>>} 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<object|null>} 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<object>} 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<object>} 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<void>}
|
||||
*/
|
||||
async function del(googleAuthId, companyId, id) {
|
||||
if (!Number.isFinite(id)) {
|
||||
throw new Error(notFound);
|
||||
|
||||
@@ -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' });
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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' });
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user