LT-115: Linking the tool data with tool group data

This commit is contained in:
Bruno Alves de Faria committed 2017-01-02 16:32:09 -02:00
1 parent f13080309e
commit d6aeebe712
5 files changed
+56 -12

No files matched your search

@@ -23,16 +23,53 @@ class MeasurementApi {
this.tools = {};
configuration.measurementTools.forEach(toolGroup => {
const collection = new Mongo.Collection(null);
collection._debugName = toolGroup.name;
collection.attachSchema(toolGroup.schema);
this.toolGroups[toolGroup.id] = collection;
const groupCollection = new Mongo.Collection(null);
groupCollection._debugName = toolGroup.name;
groupCollection.attachSchema(toolGroup.schema);
this.toolGroups[toolGroup.id] = groupCollection;
toolGroup.childTools.forEach(tool => {
const collection = new Mongo.Collection(null);
collection._debugName = tool.name;
collection.attachSchema(tool.schema);
this.tools[tool.id] = collection;
collection.find().observe({
added(measurement) {
groupCollection.insert({
toolId: tool.id,
toolItemUid: measurement._id,
createdAt: measurement.createdAt
});
const measurementCount = groupCollection.find().count();
collection.update(measurement._id, {
$set: {
measurementNumber: measurementCount
}
});
},
removedAt(measurement, atIndex) {
groupCollection.remove({
toolItemUid: measurement._id
});
toolGroup.childTools.forEach(childTool => {
this.tools[childTool.id].update({
measurementNumber: {
$gt: atIndex
}
}, {
$inc: {
measurementNumber: -1
}
}, {
multi: true
});
});
}
});
});
});
}