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:
@@ -5,7 +5,7 @@ import {
|
||||
UPDATE_MANIFEST,
|
||||
} from '../../sql/delivery.js';
|
||||
import request from '../request.js';
|
||||
import resolveCompanyAccess from '../companyuser/resolveCompanyAccess.js';
|
||||
import resolveSelectedCompanyAccess from '../companyuser/resolveSelectedCompanyAccess.js';
|
||||
import taxEnsure from '../tax/ensure.js';
|
||||
import {
|
||||
loadDelivery,
|
||||
@@ -23,14 +23,14 @@ import { assertSupplier, insertLines } from './writeLines.js';
|
||||
*
|
||||
* @example
|
||||
* const fn = update(pool);
|
||||
* const delivery = await fn(42, 1, 5, { number: 'D-2', lines: [...] });
|
||||
* const delivery = await fn(42, 5, { number: 'D-2', lines: [...] });
|
||||
* // => { id, number, type, entityId, date, lines: [...] }
|
||||
*/
|
||||
export default function update(pool) {
|
||||
const access = resolveCompanyAccess(pool);
|
||||
const access = resolveSelectedCompanyAccess(pool);
|
||||
const ensureTax = taxEnsure(pool);
|
||||
|
||||
return async (googleAuthId, companyId, id, patch = {}) => {
|
||||
return async (googleAuthId, id, patch = {}) => {
|
||||
if (!Number.isFinite(id)) {
|
||||
throw new Error('Delivery not found');
|
||||
}
|
||||
@@ -52,7 +52,7 @@ export default function update(pool) {
|
||||
normalizedLines = normalizeLines(patch.lines);
|
||||
}
|
||||
|
||||
const { rootCategoryId } = await access(googleAuthId, companyId);
|
||||
const { companyId, rootCategoryId } = await access(googleAuthId);
|
||||
|
||||
const tx = pool.transaction();
|
||||
await tx.begin();
|
||||
|
||||
Reference in New Issue
Block a user