u
This commit is contained in:
@@ -7,7 +7,6 @@ import companyDelete from './store/company/delete.js';
|
||||
import companyList from './store/company/list.js';
|
||||
import categoryGetTreeForCompany from './store/category/getTreeForCompany.js';
|
||||
import categoryCreateUnderParent from './store/category/createUnderParent.js';
|
||||
import categoryUpdateParentId from './store/category/updateParentId.js';
|
||||
import categoryDelete from './store/category/delete.js';
|
||||
import langCreate from './store/lang/create.js';
|
||||
import langDelete from './store/lang/delete.js';
|
||||
@@ -46,7 +45,6 @@ export default class LibDashStore {
|
||||
this.category = {
|
||||
getTreeForCompany: categoryGetTreeForCompany(pool),
|
||||
createUnderParent: categoryCreateUnderParent(pool),
|
||||
updateParentId: categoryUpdateParentId(pool),
|
||||
delete: categoryDelete(pool),
|
||||
};
|
||||
|
||||
|
||||
@@ -126,12 +126,6 @@ FROM category
|
||||
WHERE parent_id = @parentId
|
||||
`;
|
||||
|
||||
export const UPDATE_PARENT_ID = `
|
||||
UPDATE category
|
||||
SET parent_id = @parentId
|
||||
WHERE id = @id
|
||||
`;
|
||||
|
||||
export const DELETE = `
|
||||
DELETE FROM category
|
||||
WHERE id = @id
|
||||
|
||||
@@ -1,7 +1,16 @@
|
||||
import { DELETE } from '../../sql/category.js';
|
||||
import resolveCategoryAccess from './resolveCategoryAccess.js';
|
||||
|
||||
export default function del(pool) {
|
||||
return async (id) => {
|
||||
const access = resolveCategoryAccess(pool);
|
||||
|
||||
return async ({ googleAuthId, id }) => {
|
||||
const { rootCategoryId } = await access(googleAuthId, id);
|
||||
|
||||
if (id === rootCategoryId) {
|
||||
throw new Error('Cannot delete root category');
|
||||
}
|
||||
|
||||
await pool.request().input('id', id).query(DELETE);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
import { UPDATE_PARENT_ID } from '../../sql/category.js';
|
||||
|
||||
export default function updateParentId(pool) {
|
||||
return async (id, parentId) => {
|
||||
await pool
|
||||
.request()
|
||||
.input('id', id)
|
||||
.input('parentId', parentId)
|
||||
.query(UPDATE_PARENT_ID);
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user