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:
33
src/store/order/getById.js
Normal file
33
src/store/order/getById.js
Normal file
@@ -0,0 +1,33 @@
|
||||
import { ORDER_TYPE } from '../../sql/manifestDoc.js';
|
||||
import resolveSelectedCompanyAccess from '../companyuser/resolveSelectedCompanyAccess.js';
|
||||
import { loadDoc } from '../manifestDoc/helpers.js';
|
||||
|
||||
export default function getById(pool) {
|
||||
const access = resolveSelectedCompanyAccess(pool);
|
||||
|
||||
/**
|
||||
* Returns a single order 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 order.
|
||||
* @returns {Promise<{id: number, number: string, type: string, entityId: number|null, date: string, lines: Array<object>}>} The order with its lines.
|
||||
* @throws {Error} If the order is not found.
|
||||
*
|
||||
* @example
|
||||
* const order = await store.order.getById(42, 5);
|
||||
* // => { id, number, type, entityId, date, lines: [...] }
|
||||
*/
|
||||
return async (googleAuthId, id) => {
|
||||
if (!Number.isFinite(id)) {
|
||||
throw new Error('Order not found');
|
||||
}
|
||||
|
||||
const { companyId } = await access(googleAuthId);
|
||||
|
||||
const doc = await loadDoc(pool, null, { type: ORDER_TYPE, companyId, id });
|
||||
if (!doc) {
|
||||
throw new Error('Order not found');
|
||||
}
|
||||
return doc;
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user