cms/app-client/mirage/serializers/discourse.js
changeset 474 245b4df137d3
parent 319 78990a8a069b
child 532 1190ea937f2d
equal deleted inserted replaced
473:1b8b29c0e95c 474:245b4df137d3
     1 import { JSONAPISerializer } from 'ember-cli-mirage';
     1 import { JSONAPISerializer } from 'ember-cli-mirage';
     2 
     2 
     3 import _ from 'lodash/lodash';
     3 import _ from 'lodash/lodash';
     4 
     4 
     5 export default JSONAPISerializer.extend({
     5 export default JSONAPISerializer.extend({
     6     serialize(response) {
     6     serialize(response, request) {
     7         return { 'discourses' : _(response.models).map((discourse) => { return [discourse.id, {count: discourse.count, label: discourse.label}];}).object().value()};
     7 
       
     8       let json = JSONAPISerializer.prototype.serialize.apply(this, arguments);
       
     9 
       
    10       let qParams = request.queryParams['discourse'];
       
    11       if(qParams) {
       
    12         json =  { 'data': _.map(json.data.slice(0, json.data.length/Math.pow(2,qParams.length)), (d) => {
       
    13           let res = _.clone(d);
       
    14           res.attributes.count = Math.max(Math.floor(d.attributes.count / 2), 1);
       
    15           return res;
       
    16         })};
       
    17       }
       
    18 
       
    19       return { 'discourses' : _(json.data).map((discourse) => {
       
    20         return [
       
    21           discourse.id,
       
    22           { count: discourse.attributes.count, label: discourse.attributes.label}
       
    23         ];
       
    24       }).object().value()};
     8     }
    25     }
     9 });
    26 });