- 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
53 lines
1.7 KiB
JavaScript
53 lines
1.7 KiB
JavaScript
import { GET_BY_ID, SET_OFF, LIST_CATEGORY_IDS } from '../../sql/posterminal.js';
|
|
import resolveSelectedCompanyAccess from '../companyuser/resolveSelectedCompanyAccess.js';
|
|
|
|
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');
|
|
}
|
|
|
|
const { companyId } = await access(googleAuthId);
|
|
|
|
const existing = await pool
|
|
.request()
|
|
.input('id', posterminalId)
|
|
.query(GET_BY_ID);
|
|
|
|
if (!existing.recordset[0] || existing.recordset[0].companyId !== companyId) {
|
|
throw new Error('Posterminal not found');
|
|
}
|
|
|
|
await pool
|
|
.request()
|
|
.input('posterminalId', posterminalId)
|
|
.input('categoryId', categoryId)
|
|
.query(SET_OFF);
|
|
|
|
const result = await pool
|
|
.request()
|
|
.input('posterminalId', posterminalId)
|
|
.query(LIST_CATEGORY_IDS);
|
|
|
|
return {
|
|
id: posterminalId,
|
|
categoryIds: result.recordset.map((r) => r.categoryId),
|
|
};
|
|
};
|
|
}
|