mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
fix: preserve order when changing parent
This commit is contained in:
@@ -69,10 +69,11 @@ module.exports = function (Categories) {
|
||||
if (childrenCids.includes(newParent)) {
|
||||
throw new Error('[[error:cant-set-child-as-parent]]');
|
||||
}
|
||||
const oldParent = await Categories.getCategoryField(cid, 'parentCid');
|
||||
const categoryData = await Categories.getCategoryFields(cid, ['parentCid', 'order']);
|
||||
const oldParent = categoryData.parentCid;
|
||||
await Promise.all([
|
||||
db.sortedSetRemove(`cid:${oldParent}:children`, cid),
|
||||
db.sortedSetAdd(`cid:${newParent}:children`, cid, cid),
|
||||
db.sortedSetAdd(`cid:${newParent}:children`, categoryData.order, cid),
|
||||
db.setObjectField(`category:${cid}`, 'parentCid', newParent),
|
||||
]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user