u
This commit is contained in:
22
src/store/brand/resolveBrandAccess.js
Normal file
22
src/store/brand/resolveBrandAccess.js
Normal file
@@ -0,0 +1,22 @@
|
||||
import { GET_BY_ID_AND_COMPANY as MSSQL_GET } from '../../providers/mssql/queries/brand.js';
|
||||
import { GET_BY_ID_AND_COMPANY as SQLITE_GET } from '../../providers/sqlite3/queries/brand.js';
|
||||
import resolveSelectedCompanyAccess from '../companyuser/resolveSelectedCompanyAccess.js';
|
||||
import makeRunner from '../runner.js';
|
||||
|
||||
export default function resolveBrandAccess(provider) {
|
||||
const access = resolveSelectedCompanyAccess(provider);
|
||||
const sql = provider?.dialect === 'sqlite3' ? SQLITE_GET : MSSQL_GET;
|
||||
|
||||
return async (googleAuthId, brandId, tx) => {
|
||||
if (!Number.isFinite(brandId) || brandId <= 0) {
|
||||
throw new Error('Brand not found');
|
||||
}
|
||||
const { companyId } = await access(googleAuthId, tx);
|
||||
const runner = makeRunner(provider, tx);
|
||||
const result = await runner.query(sql, { id: brandId, companyId });
|
||||
if (!result.rows[0]) {
|
||||
throw new Error('Brand not found');
|
||||
}
|
||||
return { companyId, brand: result.rows[0] };
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user