Files
DiceCloud/app/imports/api/engine/computation/buildComputation/computeSlotQuantityFilled.js
2023-06-05 15:44:53 +02:00

21 lines
598 B
JavaScript

/**
* Only computes `totalFilled`, need to compute `quantityExpected.value`
* before `spacesLeft` can be computed
*/
export default function computeSlotQuantityFilled(node, dependencyGraph) {
let slot = node.node;
if (slot.type !== 'propertySlot') return;
slot.totalFilled = 0;
node.children.forEach(child => {
let childProp = child.node;
dependencyGraph.addLink(slot._id, childProp._id, 'slotFill');
if (
Number.isFinite(childProp.slotQuantityFilled)
) {
slot.totalFilled += childProp.slotQuantityFilled;
} else {
slot.totalFilled++;
}
});
}