Rewrite store JSDoc, split quote/order into modules, and generate typed API docs
- Rewrite JSDoc across all store methods to document the actual async methods (real params, returns, throws) instead of the internal wrappers - Split quote/order into individual module files backed by shared manifestDoc helpers; remove the createStore factory and thin wrappers - Deduplicate manifest line helpers into src/store/manifestLines.js - Extend generate-api-doc.js to render parameter/return/throws types and emit per-namespace API.<module>.md files with an API.md index - Regenerate all API docs
This commit is contained in:
@@ -1,19 +1,20 @@
|
||||
import { DELETE_BY_COMPANY_AND_ID } from '../../sql/posterminal.js';
|
||||
import resolveSelectedCompanyAccess from '../companyuser/resolveSelectedCompanyAccess.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, 5);
|
||||
*/
|
||||
export default function del(pool) {
|
||||
const access = resolveSelectedCompanyAccess(pool);
|
||||
|
||||
/**
|
||||
* Deletes a posterminal by its id within the user's selected company.
|
||||
*
|
||||
* @param {number} googleAuthId - The id of the Google auth user.
|
||||
* @param {number} id - The id of the posterminal to delete.
|
||||
* @returns {Promise<void>}
|
||||
* @throws {Error} If the posterminal is not found.
|
||||
*
|
||||
* @example
|
||||
* await store.posterminal.delete(42, 5);
|
||||
*/
|
||||
return async (googleAuthId, id) => {
|
||||
if (!Number.isFinite(id)) {
|
||||
throw new Error('Posterminal not found');
|
||||
|
||||
@@ -1,18 +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) {
|
||||
/**
|
||||
* Returns a map of category id to the posterminal ids assigned to it for a
|
||||
* company.
|
||||
*
|
||||
* @param {number} companyId - The id of the company.
|
||||
* @returns {Promise<Record<number, Array<number>>>} A map of category id to posterminal ids.
|
||||
*
|
||||
* @example
|
||||
* const map = await getCategoryPosterminalIds(pool)(1);
|
||||
* // => { 5: [1, 2], 9: [1] }
|
||||
*/
|
||||
return async (companyId) => {
|
||||
const result = await pool
|
||||
.request()
|
||||
|
||||
@@ -1,20 +1,19 @@
|
||||
import { LIST_BY_COMPANY } from '../../sql/posterminal.js';
|
||||
import resolveSelectedCompanyAccess from '../companyuser/resolveSelectedCompanyAccess.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);
|
||||
* // => [{ id, name, token, pairingpin }]
|
||||
*/
|
||||
export default function list(pool) {
|
||||
const access = resolveSelectedCompanyAccess(pool);
|
||||
|
||||
/**
|
||||
* Lists the posterminals of the user's selected company.
|
||||
*
|
||||
* @param {number} googleAuthId - The id of the Google auth user.
|
||||
* @returns {Promise<Array<{id: number, name: string, token: string, pairingpin: string}>>} The posterminals.
|
||||
*
|
||||
* @example
|
||||
* const terminals = await store.posterminal.list(42);
|
||||
* // => [{ id, name, token, pairingpin }]
|
||||
*/
|
||||
return async (googleAuthId) => {
|
||||
const { companyId } = await access(googleAuthId);
|
||||
|
||||
|
||||
@@ -1,20 +1,22 @@
|
||||
import { GET_BY_ID, SET_OFF, LIST_CATEGORY_IDS } from '../../sql/posterminal.js';
|
||||
import resolveSelectedCompanyAccess from '../companyuser/resolveSelectedCompanyAccess.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, 5, 9);
|
||||
* // => { id, categoryIds: [...] }
|
||||
*/
|
||||
export default function setOff(pool) {
|
||||
const access = resolveSelectedCompanyAccess(pool);
|
||||
|
||||
/**
|
||||
* Removes a category assignment from a posterminal (turns it off).
|
||||
*
|
||||
* @param {number} googleAuthId - The id of the Google auth user.
|
||||
* @param {number} posterminalId - The id of the posterminal.
|
||||
* @param {number} categoryId - The id of the category to remove.
|
||||
* @returns {Promise<{id: number, categoryIds: Array<number>}>} The posterminal with its remaining category ids.
|
||||
* @throws {Error} If the posterminal is not found.
|
||||
*
|
||||
* @example
|
||||
* const result = await store.posterminal.setOff(42, 5, 9);
|
||||
* // => { id, categoryIds: [...] }
|
||||
*/
|
||||
return async (googleAuthId, posterminalId, categoryId) => {
|
||||
if (!Number.isFinite(posterminalId) || !Number.isFinite(categoryId)) {
|
||||
throw new Error('Invalid posterminal or category');
|
||||
|
||||
@@ -1,20 +1,21 @@
|
||||
import { GET_BY_ID, SET_OFF_ALL, LIST_CATEGORY_IDS } from '../../sql/posterminal.js';
|
||||
import resolveSelectedCompanyAccess from '../companyuser/resolveSelectedCompanyAccess.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, 5);
|
||||
* // => { id, categoryIds: [] }
|
||||
*/
|
||||
export default function setOffAll(pool) {
|
||||
const access = resolveSelectedCompanyAccess(pool);
|
||||
|
||||
/**
|
||||
* Removes all category assignments from a posterminal.
|
||||
*
|
||||
* @param {number} googleAuthId - The id of the Google auth user.
|
||||
* @param {number} posterminalId - The id of the posterminal.
|
||||
* @returns {Promise<{id: number, categoryIds: Array<number>}>} The posterminal with an empty category list.
|
||||
* @throws {Error} If the posterminal is not found.
|
||||
*
|
||||
* @example
|
||||
* const result = await store.posterminal.setOffAll(42, 5);
|
||||
* // => { id, categoryIds: [] }
|
||||
*/
|
||||
return async (googleAuthId, posterminalId) => {
|
||||
if (!Number.isFinite(posterminalId)) {
|
||||
throw new Error('Invalid posterminal');
|
||||
|
||||
@@ -1,20 +1,22 @@
|
||||
import { GET_BY_ID, SET_ON, LIST_CATEGORY_IDS } from '../../sql/posterminal.js';
|
||||
import resolveSelectedCompanyAccess from '../companyuser/resolveSelectedCompanyAccess.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, 5, 9);
|
||||
* // => { id, categoryIds: [9, ...] }
|
||||
*/
|
||||
export default function setOn(pool) {
|
||||
const access = resolveSelectedCompanyAccess(pool);
|
||||
|
||||
/**
|
||||
* Assigns a category to a posterminal (turns it on for that category).
|
||||
*
|
||||
* @param {number} googleAuthId - The id of the Google auth user.
|
||||
* @param {number} posterminalId - The id of the posterminal.
|
||||
* @param {number} categoryId - The id of the category to assign.
|
||||
* @returns {Promise<{id: number, categoryIds: Array<number>}>} The posterminal with its category ids.
|
||||
* @throws {Error} If the posterminal is not found.
|
||||
*
|
||||
* @example
|
||||
* const result = await store.posterminal.setOn(42, 5, 9);
|
||||
* // => { id, categoryIds: [9, ...] }
|
||||
*/
|
||||
return async (googleAuthId, posterminalId, categoryId) => {
|
||||
if (!Number.isFinite(posterminalId) || !Number.isFinite(categoryId)) {
|
||||
throw new Error('Invalid posterminal or category');
|
||||
|
||||
@@ -2,20 +2,21 @@ import { GET_BY_ID, SET_ON_ALL, LIST_CATEGORY_IDS } from '../../sql/posterminal.
|
||||
import resolveSelectedCompanyAccess from '../companyuser/resolveSelectedCompanyAccess.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, 5);
|
||||
* // => { id, categoryIds: [...] }
|
||||
*/
|
||||
export default function setOnAll(pool) {
|
||||
const access = resolveSelectedCompanyAccess(pool);
|
||||
|
||||
/**
|
||||
* Assigns all categories of the user's selected company to a posterminal.
|
||||
*
|
||||
* @param {number} googleAuthId - The id of the Google auth user.
|
||||
* @param {number} posterminalId - The id of the posterminal.
|
||||
* @returns {Promise<{id: number, categoryIds: Array<number>}>} The posterminal with all category ids.
|
||||
* @throws {Error} If the posterminal is not found.
|
||||
*
|
||||
* @example
|
||||
* const result = await store.posterminal.setOnAll(42, 5);
|
||||
* // => { id, categoryIds: [...] }
|
||||
*/
|
||||
return async (googleAuthId, posterminalId) => {
|
||||
if (!Number.isFinite(posterminalId)) {
|
||||
throw new Error('Invalid posterminal');
|
||||
|
||||
@@ -1,20 +1,25 @@
|
||||
import { GET_BY_ID, CREATE, UPDATE } from '../../sql/posterminal.js';
|
||||
import resolveSelectedCompanyAccess from '../companyuser/resolveSelectedCompanyAccess.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, { name: 'Kasse 1', pairingpin: '1234', token: 'abc' });
|
||||
* // => { id, name, token, pairingpin }
|
||||
*/
|
||||
export default function upsert(pool) {
|
||||
const access = resolveSelectedCompanyAccess(pool);
|
||||
|
||||
/**
|
||||
* Creates or updates a posterminal for the user's selected company.
|
||||
*
|
||||
* @param {number} googleAuthId - The id of the Google auth user.
|
||||
* @param {object} input - The posterminal input.
|
||||
* @param {string} input.name - The posterminal name.
|
||||
* @param {string} input.pairingpin - The pairing pin.
|
||||
* @param {string} [input.token] - Optional token.
|
||||
* @param {number} [input.id] - Optional id to update an existing posterminal.
|
||||
* @returns {Promise<{id: number, name: string, token: string, pairingpin: string}>} The upserted posterminal.
|
||||
* @throws {Error} If the posterminal is invalid.
|
||||
*
|
||||
* @example
|
||||
* const terminal = await store.posterminal.upsert(42, { name: 'Kasse 1', pairingpin: '1234', token: 'abc' });
|
||||
* // => { id, name, token, pairingpin }
|
||||
*/
|
||||
return async (googleAuthId, input = {}) => {
|
||||
const name = input.name?.trim();
|
||||
if (!name) {
|
||||
|
||||
Reference in New Issue
Block a user