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:
@@ -8,20 +8,22 @@ 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, { name: 'Wholesale' });
|
||||
* // => { id, name, sort }
|
||||
*/
|
||||
export default function create(pool) {
|
||||
const access = resolveSelectedCompanyAccess(pool);
|
||||
|
||||
/**
|
||||
* Creates a new customer group for the user's selected company.
|
||||
*
|
||||
* @param {number} googleAuthId - The id of the Google auth user.
|
||||
* @param {object} input - The customer group input.
|
||||
* @param {string} input.name - The customer group name (must not be a reserved name).
|
||||
* @returns {Promise<{id: number, name: string, sort: number}>} The created customer group.
|
||||
* @throws {Error} If the name is empty or reserved.
|
||||
*
|
||||
* @example
|
||||
* const group = await store.customergroup.create(42, { name: 'Wholesale' });
|
||||
* // => { id, name, sort }
|
||||
*/
|
||||
return async (googleAuthId, { name } = {}) => {
|
||||
const cleaned = name?.trim();
|
||||
if (!cleaned) {
|
||||
|
||||
@@ -1,19 +1,20 @@
|
||||
import { DELETE_BY_COMPANY_AND_ID } from '../../sql/customergroup.js';
|
||||
import resolveSelectedCompanyAccess from '../companyuser/resolveSelectedCompanyAccess.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, 5);
|
||||
*/
|
||||
export default function del(pool) {
|
||||
const access = resolveSelectedCompanyAccess(pool);
|
||||
|
||||
/**
|
||||
* Deletes a customer group for the user's selected company by its id.
|
||||
*
|
||||
* @param {number} googleAuthId - The id of the Google auth user.
|
||||
* @param {number} id - The id of the customer group to delete.
|
||||
* @returns {Promise<void>}
|
||||
* @throws {Error} If the customer group is not found.
|
||||
*
|
||||
* @example
|
||||
* await store.customergroup.delete(42, 5);
|
||||
*/
|
||||
return async (googleAuthId, id) => {
|
||||
if (!Number.isFinite(id)) {
|
||||
throw new Error('Customer group not found');
|
||||
|
||||
@@ -1,20 +1,19 @@
|
||||
import { LIST_BY_COMPANY } from '../../sql/customergroup.js';
|
||||
import resolveSelectedCompanyAccess from '../companyuser/resolveSelectedCompanyAccess.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);
|
||||
* // => [{ id, name, sort }]
|
||||
*/
|
||||
export default function list(pool) {
|
||||
const access = resolveSelectedCompanyAccess(pool);
|
||||
|
||||
/**
|
||||
* Lists the customer groups of the user's selected company.
|
||||
*
|
||||
* @param {number} googleAuthId - The id of the Google auth user.
|
||||
* @returns {Promise<Array<{id: number, name: string, sort: number}>>} The customer groups.
|
||||
*
|
||||
* @example
|
||||
* const groups = await store.customergroup.list(42);
|
||||
* // => [{ id, name, sort }]
|
||||
*/
|
||||
return async (googleAuthId) => {
|
||||
const { companyId } = await access(googleAuthId);
|
||||
|
||||
|
||||
@@ -5,20 +5,22 @@ import {
|
||||
import request from '../request.js';
|
||||
import resolveSelectedCompanyAccess from '../companyuser/resolveSelectedCompanyAccess.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, { customergroupIds: [3, 1, 2] });
|
||||
* // => { customergroupIds: [3, 1, 2] }
|
||||
*/
|
||||
export default function order(pool) {
|
||||
const access = resolveSelectedCompanyAccess(pool);
|
||||
|
||||
/**
|
||||
* Reorders the customer groups of the user's selected company.
|
||||
*
|
||||
* @param {number} googleAuthId - The id of the Google auth user.
|
||||
* @param {object} input - The reorder input.
|
||||
* @param {Array<number>} input.customergroupIds - The customer group ids in their new order.
|
||||
* @returns {Promise<{customergroupIds: Array<number>}>} The applied order.
|
||||
* @throws {Error} If the order is invalid.
|
||||
*
|
||||
* @example
|
||||
* const result = await store.customergroup.order(42, { customergroupIds: [3, 1, 2] });
|
||||
* // => { customergroupIds: [3, 1, 2] }
|
||||
*/
|
||||
return async (googleAuthId, { customergroupIds } = {}) => {
|
||||
if (!Array.isArray(customergroupIds)) {
|
||||
throw new Error('Invalid customer group order');
|
||||
|
||||
@@ -8,20 +8,23 @@ 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, 5, { name: 'Retail' });
|
||||
* // => { id, name, sort }
|
||||
*/
|
||||
export default function update(pool) {
|
||||
const access = resolveSelectedCompanyAccess(pool);
|
||||
|
||||
/**
|
||||
* Updates the name of a customer group for the user's selected company.
|
||||
*
|
||||
* @param {number} googleAuthId - The id of the Google auth user.
|
||||
* @param {number} id - The id of the customer group to update.
|
||||
* @param {object} input - The update input.
|
||||
* @param {string} input.name - The new customer group name.
|
||||
* @returns {Promise<{id: number, name: string, sort: number}>} The updated customer group.
|
||||
* @throws {Error} If the customer group is not found or the name is empty.
|
||||
*
|
||||
* @example
|
||||
* const group = await store.customergroup.update(42, 5, { name: 'Retail' });
|
||||
* // => { id, name, sort }
|
||||
*/
|
||||
return async (googleAuthId, id, { name } = {}) => {
|
||||
if (!Number.isFinite(id)) {
|
||||
throw new Error('Customer group not found');
|
||||
|
||||
Reference in New Issue
Block a user