From a782dc3448137d20d3f84777d921e0fa451600db Mon Sep 17 00:00:00 2001
From: Vytor Calixto <vytorcalixto@gmail.com>
Date: Mon, 13 Nov 2017 10:58:37 -0200
Subject: [PATCH] Change simulation model

---
 src/libs/models/simulation.js | 110 +++-------------------------------
 1 file changed, 8 insertions(+), 102 deletions(-)

diff --git a/src/libs/models/simulation.js b/src/libs/models/simulation.js
index e70c93a9..8cbbd3a5 100644
--- a/src/libs/models/simulation.js
+++ b/src/libs/models/simulation.js
@@ -2,114 +2,20 @@ const mongoose = require('mongoose')
 
 const libs = `${process.cwd()}/libs`;
 const log = require(`${libs}/log`)(module);
+const User = require(`${libs}/models/user`);
 
 const Schema = mongoose.Schema;
 
-// Should define this somewhere else
-const MAX_SIMULATION_TIME = 10;
-
-
 let SimulationSchema = new Schema({
-    name: {
-        type: String,
+    userId: {
+        type: Schema.Types.ObjectId,
         required: true,
+        ref: 'User'
     },
-    location: Object,
-    time: Number,
-    failure_rate: Array,
-    goals_care: Array,
-    goals_inclusion: Array,
-    enrollments: Array,
-    timestamp: Date,
-});
-
-SimulationSchema.methods.setTime = function (t) {
-    t = parseInt(t, 10);
-    if (!t || t > MAX_SIMULATION_TIME) {
-        // Throw an error?
-        return false;
-    }
-    this.time = t;
-    return true;
-};
-SimulationSchema.methods.setLocation = function (l) {
-    // Should sanitize
-    this.location = l;
-    return true;
-};
-SimulationSchema.methods.setFailureRate = function (fr) {
-    // Should sanitize
-    this.failure_rate = fr;
-    return true;
-};
-SimulationSchema.methods.setCareGoals = function (g) {
-    // Should sanitize
-    this.goals_care = g;
-    return true;
-};
-SimulationSchema.methods.setInclusionGoals = function (g) {
-    // Should sanitize
-    this.goals_inclusion = g;
-    return true;
-};
-SimulationSchema.methods.setEnrollments = function (e) {
-    try{
-        e = JSON.parse(e);
-    } catch (err) {
-        return false;
-    }
-    let success = true;
-    for(let i=0; i<e.length; i++){
-        if(!(e[i] instanceof Array)){
-            return false;
-        }
-        if(e[i].length !== this.time){
-            return false;
-        }
-        e[i].forEach((n, i, array) => {
-            if(n !== parseInt(n, 10)){
-                success = false;
-            }
-        });
-
-    }
-    if (success) this.enrollments = e;
-
-    return success;
-}
-SimulationSchema.methods.update = function (property, value) {
-    let success = true;
-    switch(property){
-        case 'time':
-            if (!this.setTime(value)) success = false;
-            break;
-        case 'location':
-            if (!this.setLocation(value)) success = false;
-            break;
-        case 'failure_rate':
-            if (!this.setFailureRate(value)) success = false;
-            break;
-        case 'goals_care':
-            if (!this.setCareGoals(value)) success = false;
-            break;
-        case 'goals_inclusion':
-            if (!this.setInclusionGoals(value)) success = false;
-            break;
-        case 'enrollments':
-            if (!this.setEnrollments(value)) success = false;
-            break;
-        case 'name':
-            this.name = value;
-            break;
+    content: {
+        type: String,
+        required: true,
     }
-    return success;
-};
-
-SimulationSchema.methods.run = function () {
-    /* Runs the Simulation with given parameters */
-    // if (!this.name || !this.location || !this.time) {
-    //     console.log('This is supposed to be an error.');
-    // }
-};
+});
 
 module.exports = mongoose.model('Simulation', SimulationSchema);
-- 
GitLab