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

@@ -1,5 +1,5 @@
import { GET_BY_ID, SET_OFF_ALL, LIST_CATEGORY_IDS } from '../../sql/posterminal.js';
import resolveCompanyAccess from '../companyuser/resolveCompanyAccess.js';
import resolveSelectedCompanyAccess from '../companyuser/resolveSelectedCompanyAccess.js';
/**
* Removes all category assignments from a posterminal.
@@ -9,18 +9,18 @@ import resolveCompanyAccess from '../companyuser/resolveCompanyAccess.js';
*
* @example
* const fn = setOffAll(pool);
* const result = await fn(42, 1, 5);
* const result = await fn(42, 5);
* // => { id, categoryIds: [] }
*/
export default function setOffAll(pool) {
const access = resolveCompanyAccess(pool);
const access = resolveSelectedCompanyAccess(pool);
return async (googleAuthId, companyId, posterminalId) => {
return async (googleAuthId, posterminalId) => {
if (!Number.isFinite(posterminalId)) {
throw new Error('Invalid posterminal');
}
await access(googleAuthId, companyId);
const { companyId } = await access(googleAuthId);
// Verify posterminal belongs to company
const pt = await pool