Built motion from commit 48095ee.|0.0.102
[motion.git] / server / models / report_jscripty_question.js
index 5affcb1..127f733 100644 (file)
@@ -9,8 +9,8 @@ module.exports = function(sequelize, DataTypes) {
     question_answer: DataTypes.STRING,
     question_other_label: DataTypes.STRING,
     question_other_answer: DataTypes.STRING,
-    question_options: DataTypes.STRING
-
+    question_options: DataTypes.STRING,
+    index: DataTypes.INTEGER
   }, {
     tableName: 'report_jscripty_questions',
     associate: function(models) {
@@ -19,16 +19,20 @@ module.exports = function(sequelize, DataTypes) {
         foreignKey: 'questionId'
 
       });
-      // models.ReportJscriptyQuestion.addScope('questionSummary', function(projectId) {
-      //   return {
-      //     where: {
-      //       projectId: projectId
-      //     },
-      //     attributes: ['question_id', 'question_type', 'question_label', 'question_text', [sequelize.fn('count', sequelize.col('question_id')), 'count']],
-      //     group: ['question_id', 'question_type', 'question_label', 'question_text']
-      //   }
-      //
-      // });
+      models.ReportJscriptyQuestion.addScope('otherOption', function(projectId, questionId) {
+        return {
+          where: {
+            ProjectId: projectId,
+            question_id: questionId,
+            question_type: 'question',
+            question_other_answer: {
+              $ne: null
+            }
+          },
+          attributes: ['question_type', 'question_id', 'question_label', 'question_text', 'question_other_label', 'question_other_answer'],
+        }
+
+      });
       models.ReportJscriptyQuestion.addScope('summary', function(projectId) {
         return {
           where: {