From 5ee4529a8e8965e6a3e4d57de32be7abffb53633 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Mon, 29 Oct 2018 11:18:00 -0400 Subject: [PATCH] if source has no parentCid assume 0 --- src/categories/create.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/categories/create.js b/src/categories/create.js index 9c20522e85..cd8f7bdfe7 100644 --- a/src/categories/create.js +++ b/src/categories/create.js @@ -149,12 +149,13 @@ module.exports = function (Categories) { var tasks = []; - if (copyParent && utils.isNumber(destination.parentCid)) { - tasks.push(async.apply(db.sortedSetRemove, 'cid:' + destination.parentCid + ':children', toCid)); + const oldParent = parseInt(destination.parentCid, 10) || 0; + const newParent = parseInt(results.source.parentCid, 10) || 0; + if (copyParent) { + tasks.push(async.apply(db.sortedSetRemove, 'cid:' + oldParent + ':children', toCid)); } - - if (copyParent && utils.isNumber(results.source.parentCid)) { - tasks.push(async.apply(db.sortedSetAdd, 'cid:' + results.source.parentCid + ':children', results.source.order, toCid)); + if (copyParent) { + tasks.push(async.apply(db.sortedSetAdd, 'cid:' + newParent + ':children', results.source.order, toCid)); } destination.description = results.source.description;