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_SI } from '../../sql/unit.js';
|
||||
import resolveSelectedCompanyAccess from '../companyuser/resolveSelectedCompanyAccess.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, 'l');
|
||||
*/
|
||||
export default function del(pool) {
|
||||
const access = resolveSelectedCompanyAccess(pool);
|
||||
|
||||
/**
|
||||
* Deletes a unit for the user's selected company by its SI code.
|
||||
*
|
||||
* @param {number} googleAuthId - The id of the Google auth user.
|
||||
* @param {string} si - The SI code of the unit to delete.
|
||||
* @returns {Promise<void>}
|
||||
* @throws {Error} If the unit is not found.
|
||||
*
|
||||
* @example
|
||||
* await store.unit.delete(42, 'l');
|
||||
*/
|
||||
return async (googleAuthId, si) => {
|
||||
if (!si?.trim()) {
|
||||
throw new Error('Unit not found');
|
||||
|
||||
@@ -2,20 +2,19 @@ import { LIST_BY_COMPANY } from '../../sql/unit.js';
|
||||
import resolveSelectedCompanyAccess from '../companyuser/resolveSelectedCompanyAccess.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);
|
||||
* // => [{ id, si, basesi, basesifactor, symbol, name }]
|
||||
*/
|
||||
export default function list(pool) {
|
||||
const access = resolveSelectedCompanyAccess(pool);
|
||||
|
||||
/**
|
||||
* Lists the units available for the user's selected company.
|
||||
*
|
||||
* @param {number} googleAuthId - The id of the Google auth user.
|
||||
* @returns {Promise<Array<{id: number, si: string, basesi: string, basesifactor: number, symbol: string, name: string}>>} The units.
|
||||
*
|
||||
* @example
|
||||
* const units = await store.unit.list(42);
|
||||
* // => [{ id, si, basesi, basesifactor, symbol, name }]
|
||||
*/
|
||||
return async (googleAuthId) => {
|
||||
const { companyId, languageId } = await access(googleAuthId);
|
||||
|
||||
|
||||
@@ -30,20 +30,26 @@ 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, { si: 'l', basesi: 'm3', basesifactor: 0.001, symbol: 'L', name: 'Liter' });
|
||||
* // => { id, si, basesi, basesifactor, symbol, name }
|
||||
*/
|
||||
export default function upsert(pool) {
|
||||
const access = resolveSelectedCompanyAccess(pool);
|
||||
|
||||
/**
|
||||
* Creates or updates a unit for the user's selected company, keyed by its SI code.
|
||||
*
|
||||
* @param {number} googleAuthId - The id of the Google auth user.
|
||||
* @param {object} input - The unit input.
|
||||
* @param {string} input.si - The SI code.
|
||||
* @param {string} input.basesi - The base SI code.
|
||||
* @param {number} input.basesifactor - The base SI factor (must be > 0).
|
||||
* @param {string} input.symbol - The unit symbol.
|
||||
* @param {string} input.name - The unit name.
|
||||
* @returns {Promise<{id: number, si: string, basesi: string, basesifactor: number, symbol: string, name: string}>} The upserted unit.
|
||||
* @throws {Error} If the unit is invalid.
|
||||
*
|
||||
* @example
|
||||
* const unit = await store.unit.upsert(42, { si: 'l', basesi: 'm3', basesifactor: 0.001, symbol: 'L', name: 'Liter' });
|
||||
* // => { id, si, basesi, basesifactor, symbol, name }
|
||||
*/
|
||||
return async (googleAuthId, input) => {
|
||||
const unit = validateUnit(input);
|
||||
const { companyId, languageId } = await access(googleAuthId);
|
||||
|
||||
Reference in New Issue
Block a user