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/entityaddress.js';
import resolveCompanyAccess from '../companyuser/resolveCompanyAccess.js';
import resolveSelectedCompanyAccess from '../companyuser/resolveSelectedCompanyAccess.js';
import resolveEntityAccess from '../entity/resolveEntityAccess.js';
function shape(row) {
@@ -32,14 +32,14 @@ function optionalString(value) {
*
* @example
* const fn = create(pool);
* const address = await fn(42, 1, 5, { addressType: 'billing', street: 'Main St', city: 'Berlin' });
* const address = await fn(42, 5, { addressType: 'billing', street: 'Main St', city: 'Berlin' });
* // => { id, entityId, firstName, name, street, streetNumber, zip, city, county, addressType, 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 addressType = input.addressType?.trim?.()
? input.addressType.trim()
: null;
@@ -47,7 +47,7 @@ export default function create(pool) {
throw new Error('Address type required');
}
await access(googleAuthId, companyId);
const { companyId } = await access(googleAuthId);
await entityAccess(companyId, entityId);
let sort = input.sort;