Add entity customer numbers and scope APIs via selected company.

Entity gets an optional unique-per-company number with allocate/peek/isNumberFree helpers. Company-scoped store methods no longer take companyId and resolve google_auth.selected_company instead.
This commit is contained in:
seb
2026-08-07 04:29:35 +02:00
parent 1e89e19863
commit 70e0a9ddc4
78 changed files with 940 additions and 772 deletions

View File

@@ -3,7 +3,7 @@ import {
UPDATE_SORT,
} from '../../sql/customergroup.js';
import request from '../request.js';
import resolveCompanyAccess from '../companyuser/resolveCompanyAccess.js';
import resolveSelectedCompanyAccess from '../companyuser/resolveSelectedCompanyAccess.js';
/**
* Reorders the customer groups of a company.
@@ -13,18 +13,18 @@ import resolveCompanyAccess from '../companyuser/resolveCompanyAccess.js';
*
* @example
* const fn = order(pool);
* const result = await fn(42, 1, { customergroupIds: [3, 1, 2] });
* const result = await fn(42, { customergroupIds: [3, 1, 2] });
* // => { customergroupIds: [3, 1, 2] }
*/
export default function order(pool) {
const access = resolveCompanyAccess(pool);
const access = resolveSelectedCompanyAccess(pool);
return async (googleAuthId, companyId, { customergroupIds } = {}) => {
return async (googleAuthId, { customergroupIds } = {}) => {
if (!Array.isArray(customergroupIds)) {
throw new Error('Invalid customer group order');
}
await access(googleAuthId, companyId);
const { companyId } = await access(googleAuthId);
const groups = await pool
.request()