sqlite
This commit is contained in:
@@ -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');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user