- 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
43 lines
1.1 KiB
JavaScript
43 lines
1.1 KiB
JavaScript
import { DELETE_BY_COMPANY_AND_ID } from '../../sql/brand.js';
|
|
import resolveSelectedCompanyAccess from '../companyuser/resolveSelectedCompanyAccess.js';
|
|
|
|
export default function del(pool) {
|
|
const access = resolveSelectedCompanyAccess(pool);
|
|
|
|
/**
|
|
* Deletes a brand 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 brand to delete.
|
|
* @returns {Promise<void>}
|
|
* @throws {Error} If the brand is not found.
|
|
*
|
|
* @example
|
|
* await store.brand.delete(42, 3);
|
|
*/
|
|
return async (googleAuthId, id) => {
|
|
if (!Number.isFinite(id)) {
|
|
throw new Error('Brand not found');
|
|
}
|
|
|
|
const { companyId } = await access(googleAuthId);
|
|
|
|
try {
|
|
const result = await pool
|
|
.request()
|
|
.input('id', id)
|
|
.input('companyId', companyId)
|
|
.query(DELETE_BY_COMPANY_AND_ID);
|
|
|
|
if (!result.rowsAffected[0]) {
|
|
throw new Error('Brand not found');
|
|
}
|
|
} catch (err) {
|
|
if (err.number === 547) {
|
|
throw new Error('Brand in use');
|
|
}
|
|
throw err;
|
|
}
|
|
};
|
|
}
|