fix: preserve order when changing parent

v1.18.x
Barış Soner Uşaklı 4 years ago
parent 3c4e93a3c1
commit 2ceda70a97

@ -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),
]);

Loading…
Cancel
Save