From 8268ea85ce6b8fd346e886432b0b4f8c02075993 Mon Sep 17 00:00:00 2001 From: ThaumRystra Date: Sun, 3 Nov 2024 16:15:22 +0200 Subject: [PATCH] Fixed duplicating properties losing their children --- .../methods/duplicateProperty.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/app/imports/api/creature/creatureProperties/methods/duplicateProperty.js b/app/imports/api/creature/creatureProperties/methods/duplicateProperty.js index 7c1b1aa7..8cd7c52b 100644 --- a/app/imports/api/creature/creatureProperties/methods/duplicateProperty.js +++ b/app/imports/api/creature/creatureProperties/methods/duplicateProperty.js @@ -35,13 +35,13 @@ const duplicateProperty = new ValidatedMethod({ let property = CreatureProperties.findOne(_id); if (!property) throw new Meteor.Error('not-found', 'The source property was not found'); - let creature = getRootCreatureAncestor(property); + const creature = getRootCreatureAncestor(property); assertEditPermission(creature, this.userId); // Renew the doc ID - let randomSrc = DDP.randomStream('duplicateProperty'); - let propertyId = randomSrc.id(); + const randomSrc = DDP.randomStream('duplicateProperty'); + const propertyId = randomSrc.id(); property._id = propertyId; // Change the variableName so it isn't immediately overridden @@ -50,7 +50,7 @@ const duplicateProperty = new ValidatedMethod({ } // Get all the descendants - let nodes = CreatureProperties.find({ + const nodes = CreatureProperties.find({ ...getFilter.descendants(property), removed: { $ne: true }, }, { @@ -70,7 +70,13 @@ const duplicateProperty = new ValidatedMethod({ // Give the docs new IDs without breaking internal references const allNodes = [property, ...nodes]; - renewDocIds({ docArray: allNodes }); + renewDocIds({ + docArray: allNodes, + idMap: { + [_id]: propertyId, + [propertyId]: propertyId, + }, + }); // Order the root node property.left = Number.MAX_SAFE_INTEGER - 1;