Files
zkldi_Tachi/database-seeds/scripts/mutations.js
T
2022-01-31 19:23:18 +00:00

30 lines
610 B
JavaScript

const { MutateCollection, EfficientInPlaceDeepmerge } = require("./util");
function DoesMatchCriteria(element, mutation) {
for (const [key, value] of Object.entries(mutation.match)) {
if (element[key] !== value) {
return false;
}
}
return true;
}
function ApplyMutations(name, mutations) {
MutateCollection(name, (collection) => {
for (const element of collection) {
for (const mutation of mutations) {
if (DoesMatchCriteria(element, mutation)) {
EfficientInPlaceDeepmerge(element, mutation.data);
}
}
}
return collection;
});
}
module.exports = {
ApplyMutations,
};