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:
@@ -12,21 +12,26 @@ 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, 5, { contactType: 'email', contact: 'a@b.c' });
|
||||
* // => { id, entityId, contactType, contact, sort }
|
||||
*/
|
||||
export default function create(pool) {
|
||||
const access = resolveSelectedCompanyAccess(pool);
|
||||
const entityAccess = resolveEntityAccess(pool);
|
||||
|
||||
/**
|
||||
* Creates a new contact for an entity.
|
||||
*
|
||||
* @param {number} googleAuthId - The id of the Google auth user.
|
||||
* @param {number} entityId - The id of the entity.
|
||||
* @param {object} input - The contact input.
|
||||
* @param {string} input.contactType - The contact type (e.g. `'email'`).
|
||||
* @param {string} input.contact - The contact value.
|
||||
* @param {number} [input.sort] - Optional sort order.
|
||||
* @returns {Promise<{id: number, entityId: number, contactType: string, contact: string, sort: number}>} The created contact.
|
||||
* @throws {Error} If the contact type or value is missing.
|
||||
*
|
||||
* @example
|
||||
* const contact = await store.entitycontact.create(42, 5, { contactType: 'email', contact: 'a@b.c' });
|
||||
* // => { id, entityId, contactType, contact, sort }
|
||||
*/
|
||||
return async (googleAuthId, entityId, input = {}) => {
|
||||
const contactType = input.contactType?.trim?.()
|
||||
? input.contactType.trim()
|
||||
|
||||
@@ -2,20 +2,22 @@ import { DELETE_BY_ENTITY_AND_ID } from '../../sql/entitycontact.js';
|
||||
import resolveSelectedCompanyAccess from '../companyuser/resolveSelectedCompanyAccess.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, 5, 9);
|
||||
*/
|
||||
export default function del(pool) {
|
||||
const access = resolveSelectedCompanyAccess(pool);
|
||||
const entityAccess = resolveEntityAccess(pool);
|
||||
|
||||
/**
|
||||
* Deletes a contact of an entity.
|
||||
*
|
||||
* @param {number} googleAuthId - The id of the Google auth user.
|
||||
* @param {number} entityId - The id of the entity.
|
||||
* @param {number} id - The id of the contact to delete.
|
||||
* @returns {Promise<void>}
|
||||
* @throws {Error} If the contact is not found.
|
||||
*
|
||||
* @example
|
||||
* await store.entitycontact.delete(42, 5, 9);
|
||||
*/
|
||||
return async (googleAuthId, entityId, id) => {
|
||||
if (!Number.isFinite(id)) {
|
||||
throw new Error('Contact not found');
|
||||
|
||||
@@ -12,21 +12,21 @@ 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, 5);
|
||||
* // => [{ id, entityId, contactType, contact, sort }]
|
||||
*/
|
||||
export default function list(pool) {
|
||||
const access = resolveSelectedCompanyAccess(pool);
|
||||
const entityAccess = resolveEntityAccess(pool);
|
||||
|
||||
/**
|
||||
* Lists the contacts of an entity.
|
||||
*
|
||||
* @param {number} googleAuthId - The id of the Google auth user.
|
||||
* @param {number} entityId - The id of the entity.
|
||||
* @returns {Promise<Array<{id: number, entityId: number, contactType: string, contact: string, sort: number}>>} The contacts.
|
||||
*
|
||||
* @example
|
||||
* const contacts = await store.entitycontact.list(42, 5);
|
||||
* // => [{ id, entityId, contactType, contact, sort }]
|
||||
*/
|
||||
return async (googleAuthId, entityId) => {
|
||||
const { companyId } = await access(googleAuthId);
|
||||
await entityAccess(companyId, entityId);
|
||||
|
||||
@@ -12,21 +12,24 @@ 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, 5, 9, { contact: 'b@c.d' });
|
||||
* // => { id, entityId, contactType, contact, sort }
|
||||
*/
|
||||
export default function update(pool) {
|
||||
const access = resolveSelectedCompanyAccess(pool);
|
||||
const entityAccess = resolveEntityAccess(pool);
|
||||
|
||||
/**
|
||||
* Updates a contact of an entity.
|
||||
*
|
||||
* @param {number} googleAuthId - The id of the Google auth user.
|
||||
* @param {number} entityId - The id of the entity.
|
||||
* @param {number} id - The id of the contact to update.
|
||||
* @param {object} patch - The update patch (any subset of contact fields).
|
||||
* @returns {Promise<{id: number, entityId: number, contactType: string, contact: string, sort: number}>} The updated contact.
|
||||
* @throws {Error} If the contact is not found.
|
||||
*
|
||||
* @example
|
||||
* const contact = await store.entitycontact.update(42, 5, 9, { contact: 'b@c.d' });
|
||||
* // => { id, entityId, contactType, contact, sort }
|
||||
*/
|
||||
return async (googleAuthId, entityId, id, patch = {}) => {
|
||||
if (!Number.isFinite(id)) {
|
||||
throw new Error('Contact not found');
|
||||
|
||||
Reference in New Issue
Block a user