cms/app-client/mirage/serializers/language.js
author ymh <ymh.work@gmail.com>
Sat, 10 Jun 2017 08:33:03 +0200
changeset 532 1190ea937f2d
parent 474 245b4df137d3
permissions -rw-r--r--
make things work after node 8, npm 5 migration. Migrate to lodash 4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
173
cf7b221238fd Work on test fixtures:
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
import { JSONAPISerializer } from 'ember-cli-mirage';
cf7b221238fd Work on test fixtures:
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
532
1190ea937f2d make things work after node 8, npm 5 migration. Migrate to lodash 4
ymh <ymh.work@gmail.com>
parents: 474
diff changeset
     3
import _ from 'lodash';
173
cf7b221238fd Work on test fixtures:
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
cf7b221238fd Work on test fixtures:
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
export default JSONAPISerializer.extend({
474
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 319
diff changeset
     6
    serialize(response, request) {
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 319
diff changeset
     7
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 319
diff changeset
     8
      let json = JSONAPISerializer.prototype.serialize.apply(this, arguments);
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 319
diff changeset
     9
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 319
diff changeset
    10
      let qParams = request.queryParams['discourse'];
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 319
diff changeset
    11
      if(qParams) {
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 319
diff changeset
    12
        json =  { 'data': _.map(json.data.slice(0, json.data.length/Math.pow(2,qParams.length)), (lang) => {
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 319
diff changeset
    13
          let resLang = _.clone(lang);
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 319
diff changeset
    14
          resLang.attributes.count = Math.max(Math.floor(resLang.attributes.count / 2), 1);
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 319
diff changeset
    15
          return resLang;
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 319
diff changeset
    16
        })};
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 319
diff changeset
    17
      }
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 319
diff changeset
    18
532
1190ea937f2d make things work after node 8, npm 5 migration. Migrate to lodash 4
ymh <ymh.work@gmail.com>
parents: 474
diff changeset
    19
      return {'languages' : _(json.data).map((lang) => { return [lang.id, lang.attributes.count];}).fromPairs().value()};
173
cf7b221238fd Work on test fixtures:
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
    }
cf7b221238fd Work on test fixtures:
ymh <ymh.work@gmail.com>
parents:
diff changeset
    21
});