Built motion from commit c2984ba.|0.0.114
[motion.git] / server / models / analytics_custom_report.js
index 3063813..59dd1b7 100644 (file)
@@ -22,9 +22,32 @@ module.exports = function(sequelize, DataTypes) {
           model: models.ReportField,
           as: 'Fields',
           required: false,
-          attributes: ['field', 'alias', 'function', 'groupBy', 'orderBy', 'MetricId']
+          attributes: ['field', 'alias', 'function', 'groupBy', 'orderBy', 'MetricId', 'format', 'custom'],
         }]
       });
+
+      CustomReport.addScope('exportFields', function(query) {
+        return {
+          include: [{
+            model: models.ReportField,
+            as: 'Fields',
+            required: false,
+            attributes: ['field', 'alias', 'function', 'groupBy', 'orderBy', 'MetricId', 'format', 'custom'],
+            include: [{
+              model: models.Metric,
+              attributes: ['description', 'metric', 'name', 'table'],
+              required: false,
+              include: [{
+                model: models.ReportField,
+                as: 'ReportFields',
+                attributes: ['field', 'alias', 'function', 'groupBy', 'orderBy', 'format'],
+                required: false,
+                where: query
+              }],
+            }]
+          }]
+        };
+      });
     }
   });