This commit is contained in:
seb
2026-09-22 07:25:16 +02:00
parent 4ed6260e91
commit cca131d83a
148 changed files with 5343 additions and 3466 deletions

View File

@@ -1,19 +1,25 @@
import { GET_BY_COMPANY_AND_ID } from '../../providers/mssql/queries/customergroup.js';
import request from '../request.js';
import { GET_BY_COMPANY_AND_ID as MSSQL_GET_BY_COMPANY_AND_ID } from '../../providers/mssql/queries/customergroup.js';
import { GET_BY_COMPANY_AND_ID as SQLITE_GET_BY_COMPANY_AND_ID } from '../../providers/sqlite3/queries/customergroup.js';
import makeRunner from '../runner.js';
/** Ensure customergroup belongs to company. Throws Customer group not found. */
export default function resolveCustomerGroupAccess(pool) {
export default function resolveCustomerGroupAccess(provider) {
const sql =
provider?.dialect === 'sqlite3'
? SQLITE_GET_BY_COMPANY_AND_ID
: MSSQL_GET_BY_COMPANY_AND_ID;
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 result = await makeRunner(provider, tx).query(sql, {
id: customergroupId,
companyId,
});
const row = result.recordset[0];
const row = result.rows[0];
if (!row) {
throw new Error('Customer group not found');
}