Skip to content
Snippets Groups Projects
Commit 56cee352 authored by Rudolf Copi Eckelberg's avatar Rudolf Copi Eckelberg
Browse files

Changed update to methods

parent 2bfdf1fb
No related branches found
No related tags found
2 merge requests!116Release v1.0.0,!25Auth
Pipeline #
......@@ -24,30 +24,38 @@ let SimulationSchema = new Schema({
goals_inclusion: Array,
});
SimulationSchema.methods.setTime = (t) => {
SimulationSchema.methods.setTime = function (t) {
t = parseInt(t, 10);
if(!t || t>MAX_SIMULATION_TIME){
if (!t || t > MAX_SIMULATION_TIME) {
// Throw an error?
return;
}
this.time = t;
};
SimulationSchema.methods.setLocation = (l) => {
SimulationSchema.methods.setLocation = function (l) {
// Should sanitize
if(!(l instanceof locations.location)){
// Throw an error?
return;
}
this.location = l;
};
SimulationSchema.methods.setCareGoals = (g) => {
SimulationSchema.methods.setFailureRate = function (fr) {
// Should sanitize
this.goals.care = g;
this.failure_rate = fr;
};
SimulationSchema.methods.setInclusionGoals = (g) => {
SimulationSchema.methods.setCareGoals = function (g) {
// Should sanitize
this.goals.inclusion = g;
this.goals_care = g;
};
SimulationSchema.methods.setInclusionGoals = function (g) {
// Should sanitize
this.goals_inclusion = g;
};
SimulationSchema.methods.update = function (property, value) {
if (property === "time") this.setTime(value);
if (property === "location") this.setLocation(value);
if (property === "failure_rate") this.setFailureRate(value);
if (property === "goals_care") this.setCareGoals(value);
if (property === "goals_inclusion") this.setInclusionGoals(value);
};
SimulationSchema.methods.run = () => {
/* Runs the Simulation with given parameters */
// if (!this.name || !this.location || !this.time) {
......
......@@ -85,8 +85,8 @@ simulationApp.post('/:id', (req, res, next) => {
});
}, (req, res) => {
for (let property in req.body) {
if(Simulation.schema.tree.hasOwnProperty(property)) {
req.simulation[property] = req.body[property];
if (Simulation.schema.tree.hasOwnProperty(property)) {
req.simulation.update(property, req.body[property]);
}
}
req.simulation.save((err) => {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment