refactor(socket.io): deprecate categories.get in favour of api.categories.list

This commit is contained in:
Julian Lam
2023-10-19 10:21:51 -04:00
parent 52b78e83a8
commit 96046373da
4 changed files with 24 additions and 9 deletions

View File

@@ -15,6 +15,22 @@ const hasAdminPrivilege = async (uid, privilege = 'categories') => {
}
};
categoriesAPI.list = async (caller) => {
async function getCategories() {
const cids = await categories.getCidsByPrivilege('categories:cid', caller.uid, 'find');
return await categories.getCategoriesData(cids);
}
const [isAdmin, categoriesData] = await Promise.all([
user.isAdministrator(caller.uid),
getCategories(),
]);
return {
categories: categoriesData.filter(category => category && (!category.disabled || isAdmin)),
};
};
categoriesAPI.get = async function (caller, data) {
const [userPrivileges, category] = await Promise.all([
privileges.categories.get(data.cid, caller.uid),