mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
feat: #9294, put new categories at top
This commit is contained in:
@@ -13,11 +13,15 @@ const cache = require('../cache');
|
||||
module.exports = function (Categories) {
|
||||
Categories.create = async function (data) {
|
||||
const parentCid = data.parentCid ? data.parentCid : 0;
|
||||
const cid = await db.incrObjectField('global', 'nextCid');
|
||||
const [cid, firstChild] = await Promise.all([
|
||||
db.incrObjectField('global', 'nextCid'),
|
||||
db.getSortedSetRangeWithScores(`cid:${parentCid}:children`, 0, 0),
|
||||
]);
|
||||
|
||||
data.name = String(data.name || `Category ${cid}`);
|
||||
const slug = `${cid}/${slugify(data.name)}`;
|
||||
const order = data.order || cid; // If no order provided, place it at the end
|
||||
const smallestOrder = firstChild.length ? firstChild[0].score - 1 : 1;
|
||||
const order = data.order || smallestOrder; // If no order provided, place it at the top
|
||||
const colours = Categories.assignColours();
|
||||
|
||||
let category = {
|
||||
|
||||
Reference in New Issue
Block a user