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,7 +1,7 @@
|
||||
import { CREATE } from '../../sql/entity.js';
|
||||
import { INSERT as INSERT_HISTORY } from '../../sql/entityhistory.js';
|
||||
import request from '../request.js';
|
||||
import resolveCompanyAccess from '../companyuser/resolveCompanyAccess.js';
|
||||
import resolveSelectedCompanyAccess from '../companyuser/resolveSelectedCompanyAccess.js';
|
||||
import ensureLieferantenGroup from './ensureLieferantenGroup.js';
|
||||
|
||||
/**
|
||||
@@ -12,19 +12,19 @@ import ensureLieferantenGroup from './ensureLieferantenGroup.js';
|
||||
*
|
||||
* @example
|
||||
* const fn = create(pool);
|
||||
* const supplier = await fn(42, 1, { name: 'Acme Supplies' });
|
||||
* const supplier = await fn(42, { name: 'Acme Supplies' });
|
||||
* // => { id, name, createdAt, updatedAt }
|
||||
*/
|
||||
export default function create(pool) {
|
||||
const access = resolveCompanyAccess(pool);
|
||||
const access = resolveSelectedCompanyAccess(pool);
|
||||
|
||||
return async (googleAuthId, companyId, { name } = {}) => {
|
||||
return async (googleAuthId, { name } = {}) => {
|
||||
const cleaned = name?.trim();
|
||||
if (!cleaned) {
|
||||
throw new Error('Name required');
|
||||
}
|
||||
|
||||
const { companyuserId } = await access(googleAuthId, companyId);
|
||||
const { companyId, companyuserId } = await access(googleAuthId);
|
||||
|
||||
const tx = pool.transaction();
|
||||
await tx.begin();
|
||||
@@ -36,6 +36,7 @@ export default function create(pool) {
|
||||
.input('customergroupId', customergroupId)
|
||||
.input('firstName', null)
|
||||
.input('name', cleaned)
|
||||
.input('number', null)
|
||||
.query(CREATE);
|
||||
|
||||
const row = created.recordset[0];
|
||||
|
||||
Reference in New Issue
Block a user