Node.js based forum software built for the modern web
feat: #9294, put new categories at top
Barış Soner Uşaklı4b2bf12fd1d7
diff --git a/src/categories/create.js b/src/categories/create.jsindex d5246dd497..a27f0954aa 100644--- a/src/categories/create.js+++ b/src/categories/create.js@@ -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 topconst colours = Categories.assignColours();let category = {