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