author | ymh <ymh.work@gmail.com> |
Sat, 10 Jun 2017 08:33:03 +0200 | |
changeset 532 | 1190ea937f2d |
parent 474 | 245b4df137d3 |
permissions | -rw-r--r-- |
173 | 1 |
import { JSONAPISerializer } from 'ember-cli-mirage'; |
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 | 4 |
|
5 |
export default JSONAPISerializer.extend({ |
|
474 | 6 |
serialize(response, request) { |
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)), (lang) => { |
|
13 |
let resLang = _.clone(lang); |
|
14 |
resLang.attributes.count = Math.max(Math.floor(resLang.attributes.count / 2), 1); |
|
15 |
return resLang; |
|
16 |
})}; |
|
17 |
} |
|
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 | 20 |
} |
21 |
}); |