173
|
1 |
import { JSONAPISerializer } from 'ember-cli-mirage'; |
|
2 |
|
|
3 |
import _ from 'lodash/lodash'; |
|
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 |
]; |
|
24 |
}).object().value()}; |
173
|
25 |
} |
|
26 |
}); |