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 { DELETE_BY_ENTITY_AND_ID } from '../../sql/entitycontact.js';
import resolveCompanyAccess from '../companyuser/resolveCompanyAccess.js';
import resolveSelectedCompanyAccess from '../companyuser/resolveSelectedCompanyAccess.js';
import resolveEntityAccess from '../entity/resolveEntityAccess.js';
/**
@@ -10,18 +10,18 @@ import resolveEntityAccess from '../entity/resolveEntityAccess.js';
*
* @example
* const fn = del(pool);
* await fn(42, 1, 5, 9);
* await fn(42, 5, 9);
*/
export default function del(pool) {
const access = resolveCompanyAccess(pool);
const access = resolveSelectedCompanyAccess(pool);
const entityAccess = resolveEntityAccess(pool);
return async (googleAuthId, companyId, entityId, id) => {
return async (googleAuthId, entityId, id) => {
if (!Number.isFinite(id)) {
throw new Error('Contact not found');
}
await access(googleAuthId, companyId);
const { companyId } = await access(googleAuthId);
await entityAccess(companyId, entityId);
const result = await pool