1 // mirage/serializers/blog-post.js |
1 // mirage/serializers/blog-post.js |
2 import BaseSerializer from './application'; |
2 import BaseSerializer from './application'; |
3 import _ from 'lodash'; |
3 import _ from 'lodash'; |
4 |
4 |
5 export default BaseSerializer.extend({ |
5 export default BaseSerializer.extend({ |
6 attrs: ['id', 'title', 'language', 'url', 'issued', 'modified', 'publishers', 'mediaArray'], |
6 attrs: ['id', 'title', 'language', 'url', 'issued', 'modified', 'publishers', 'mediaArray', 'transcript'], |
7 |
7 |
8 serialize(response, request) { |
8 serialize(response, request) { |
9 |
9 |
10 console.log(request, response); |
10 console.log(request, response); |
11 // This is how to call super, as Mirage borrows [Backbone's implementation of extend](http://backbonejs.org/#Model-extend) |
11 // This is how to call super, as Mirage borrows [Backbone's implementation of extend](http://backbonejs.org/#Model-extend) |
12 let json = BaseSerializer.prototype.serialize.apply(this, arguments); |
12 let json = BaseSerializer.prototype.serialize.apply(this, arguments); |
13 |
13 |
14 json['documents'] = _.map(json['documents'], function(doc) { |
14 json['documents'] = _.map(json['documents'], function(doc) { |
15 let res = _.omit(doc, ['publishers', 'mediaArray']); |
15 let res = _.omit(doc, ['publishers', 'mediaArray', 'transcript']); |
16 res['publisher'] = doc['publishers'].join(', '); |
16 res['publisher'] = doc['publishers'].join(', '); |
17 res['duration_ms'] = doc['mediaArray']?doc['mediaArray'][_(Object.keys(doc['mediaArray'])).first()]['extent_ms']:0; |
17 res['duration_ms'] = doc['mediaArray']?doc['mediaArray'][_(Object.keys(doc['mediaArray'])).first()]['extent_ms']:0; |
|
18 res['transcript_url'] = (doc['transcript'] && doc['transcript']['url'])?doc['transcript']['url']:null; |
18 return res; |
19 return res; |
19 }); |
20 }); |
20 |
21 |
21 return json; |
22 return json; |
22 } |
23 } |