You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
nodebb/src/api/categories.js

42 lines
1.0 KiB
JavaScript

'use strict';
const categories = require('../categories');
const events = require('../events');
const privileges = require('../privileges');
const categoriesAPI = module.exports;
categoriesAPI.get = async function (caller, data) {
const [userPrivileges, category] = await Promise.all([
privileges.categories.get(data.cid, caller.uid),
categories.getCategoryData(data.cid),
]);
if (!category || !userPrivileges.read) {
return null;
}
return category;
};
categoriesAPI.create = async function (caller, data) {
const response = await categories.create(data);
const categoryObjs = await categories.getCategories([response.cid], caller.uid);
return categoryObjs[0];
};
categoriesAPI.update = async function (caller, data) {
await categories.update(data);
};
categoriesAPI.delete = async function (caller, data) {
const name = await categories.getCategoryField(data.cid, 'name');
await categories.purge(data.cid, caller.uid);
await events.log({
type: 'category-purge',
uid: caller.uid,
ip: caller.ip,
cid: data.cid,
name: name,
});
};