author | ymh <ymh.work@gmail.com> |
Fri, 08 Sep 2017 15:03:29 +0200 | |
changeset 543 | aaaf9b0b09f6 |
parent 532 | 1190ea937f2d |
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)), (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 |
]; |
|
532
1190ea937f2d
make things work after node 8, npm 5 migration. Migrate to lodash 4
ymh <ymh.work@gmail.com>
parents:
474
diff
changeset
|
24 |
}).fromPairs().value()}; |
173 | 25 |
} |
26 |
}); |