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; }; }