u
This commit is contained in:
17
src/store/category/getTreeForCompany.js
Normal file
17
src/store/category/getTreeForCompany.js
Normal file
@@ -0,0 +1,17 @@
|
||||
import { GET_TREE } from '../../sql/category.js';
|
||||
import resolveCompanyAccess from '../companyuser/resolveCompanyAccess.js';
|
||||
|
||||
export default function getTreeForCompany(pool) {
|
||||
const access = resolveCompanyAccess(pool);
|
||||
|
||||
return async (authId, companyId) => {
|
||||
const { rootCategoryId } = await access(authId, companyId);
|
||||
|
||||
const result = await pool
|
||||
.request()
|
||||
.input('rootId', rootCategoryId)
|
||||
.query(GET_TREE);
|
||||
|
||||
return result.recordset;
|
||||
};
|
||||
}
|
||||
24
src/store/companyuser/resolveCompanyAccess.js
Normal file
24
src/store/companyuser/resolveCompanyAccess.js
Normal file
@@ -0,0 +1,24 @@
|
||||
import { GET_COMPANY_ACCESS } from '../../sql/companyuser.js';
|
||||
|
||||
export default function resolveCompanyAccess(pool) {
|
||||
return async (authId, companyId) => {
|
||||
const result = await pool
|
||||
.request()
|
||||
.input('authId', authId)
|
||||
.input('companyId', companyId)
|
||||
.query(GET_COMPANY_ACCESS);
|
||||
|
||||
const row = result.recordset[0];
|
||||
if (!row) {
|
||||
throw new Error('Company not found');
|
||||
}
|
||||
if (!row.companyuserId) {
|
||||
throw new Error('Not authorized');
|
||||
}
|
||||
if (!row.rootCategoryId) {
|
||||
throw new Error('Company not found');
|
||||
}
|
||||
|
||||
return { rootCategoryId: row.rootCategoryId };
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user