Add entity address/contact tables and CRUD for entity resources
This commit is contained in:
22
src/store/customergroup/resolveCustomerGroupAccess.js
Normal file
22
src/store/customergroup/resolveCustomerGroupAccess.js
Normal file
@@ -0,0 +1,22 @@
|
||||
import { GET_BY_COMPANY_AND_ID } from '../../sql/customergroup.js';
|
||||
import request from '../request.js';
|
||||
|
||||
/** Ensure customergroup belongs to company. Throws Customer group not found. */
|
||||
export default function resolveCustomerGroupAccess(pool) {
|
||||
return async (companyId, customergroupId, tx) => {
|
||||
if (!Number.isFinite(customergroupId)) {
|
||||
throw new Error('Customer group not found');
|
||||
}
|
||||
|
||||
const result = await request(pool, tx)
|
||||
.input('id', customergroupId)
|
||||
.input('companyId', companyId)
|
||||
.query(GET_BY_COMPANY_AND_ID);
|
||||
|
||||
const row = result.recordset[0];
|
||||
if (!row) {
|
||||
throw new Error('Customer group not found');
|
||||
}
|
||||
return row;
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user