Fixed duplicating properties losing their children

This commit is contained in:
ThaumRystra
2024-11-03 16:15:22 +02:00
parent f8708b0c31
commit 8268ea85ce

View File

@@ -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;