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 { CREATE, GET_NEXT_SORT } from '../../sql/entitycontact.js';
import resolveCompanyAccess from '../companyuser/resolveCompanyAccess.js';
import resolveSelectedCompanyAccess from '../companyuser/resolveSelectedCompanyAccess.js';
import resolveEntityAccess from '../entity/resolveEntityAccess.js';
function shape(row) {
@@ -20,14 +20,14 @@ function shape(row) {
*
* @example
* const fn = create(pool);
* const contact = await fn(42, 1, 5, { contactType: 'email', contact: 'a@b.c' });
* const contact = await fn(42, 5, { contactType: 'email', contact: 'a@b.c' });
* // => { id, entityId, contactType, contact, sort }
*/
export default function create(pool) {
const access = resolveCompanyAccess(pool);
const access = resolveSelectedCompanyAccess(pool);
const entityAccess = resolveEntityAccess(pool);
return async (googleAuthId, companyId, entityId, input = {}) => {
return async (googleAuthId, entityId, input = {}) => {
const contactType = input.contactType?.trim?.()
? input.contactType.trim()
: null;
@@ -36,7 +36,7 @@ export default function create(pool) {
throw new Error('Contact required');
}
await access(googleAuthId, companyId);
const { companyId } = await access(googleAuthId);
await entityAccess(companyId, entityId);
let sort = input.sort;