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:
@@ -1,4 +1,4 @@
|
||||
import resolveCompanyAccess from '../companyuser/resolveCompanyAccess.js';
|
||||
import resolveSelectedCompanyAccess from '../companyuser/resolveSelectedCompanyAccess.js';
|
||||
import { loadDelivery } from './helpers.js';
|
||||
|
||||
/**
|
||||
@@ -9,18 +9,18 @@ import { loadDelivery } from './helpers.js';
|
||||
*
|
||||
* @example
|
||||
* const fn = getById(pool);
|
||||
* const delivery = await fn(42, 1, 5);
|
||||
* const delivery = await fn(42, 5);
|
||||
* // => { id, number, type, entityId, date, lines: [...] }
|
||||
*/
|
||||
export default function getById(pool) {
|
||||
const access = resolveCompanyAccess(pool);
|
||||
const access = resolveSelectedCompanyAccess(pool);
|
||||
|
||||
return async (googleAuthId, companyId, id) => {
|
||||
return async (googleAuthId, id) => {
|
||||
if (!Number.isFinite(id)) {
|
||||
throw new Error('Delivery not found');
|
||||
}
|
||||
|
||||
await access(googleAuthId, companyId);
|
||||
const { companyId } = await access(googleAuthId);
|
||||
|
||||
const delivery = await loadDelivery(pool, null, companyId, id);
|
||||
if (!delivery) {
|
||||
|
||||
Reference in New Issue
Block a user