cms/app-client/mirage/serializers/discourse.js
changeset 474 245b4df137d3
parent 319 78990a8a069b
child 532 1190ea937f2d
--- a/cms/app-client/mirage/serializers/discourse.js	Tue Dec 13 23:30:54 2016 +0100
+++ b/cms/app-client/mirage/serializers/discourse.js	Fri Dec 16 17:43:07 2016 +0100
@@ -3,7 +3,24 @@
 import _ from 'lodash/lodash';
 
 export default JSONAPISerializer.extend({
-    serialize(response) {
-        return { 'discourses' : _(response.models).map((discourse) => { return [discourse.id, {count: discourse.count, label: discourse.label}];}).object().value()};
+    serialize(response, request) {
+
+      let json = JSONAPISerializer.prototype.serialize.apply(this, arguments);
+
+      let qParams = request.queryParams['discourse'];
+      if(qParams) {
+        json =  { 'data': _.map(json.data.slice(0, json.data.length/Math.pow(2,qParams.length)), (d) => {
+          let res = _.clone(d);
+          res.attributes.count = Math.max(Math.floor(d.attributes.count / 2), 1);
+          return res;
+        })};
+      }
+
+      return { 'discourses' : _(json.data).map((discourse) => {
+        return [
+          discourse.id,
+          { count: discourse.attributes.count, label: discourse.attributes.label}
+        ];
+      }).object().value()};
     }
 });