2017-01-02 21:49:44 +03:00
|
|
|
import BaseSerializer from './application';
|
|
|
|
import {RestSerializer} from 'ember-cli-mirage';
|
|
|
|
|
|
|
|
export default BaseSerializer.extend({
|
2018-03-19 12:53:17 +03:00
|
|
|
embed: true,
|
|
|
|
|
|
|
|
include(request) {
|
|
|
|
if (request.queryParams.include && request.queryParams.include.indexOf('roles') >= 0) {
|
|
|
|
return ['roles'];
|
|
|
|
}
|
|
|
|
|
|
|
|
return [];
|
|
|
|
},
|
|
|
|
|
2017-01-02 21:49:44 +03:00
|
|
|
serialize(object, request) {
|
|
|
|
if (this.isCollection(object)) {
|
2018-03-13 14:17:29 +03:00
|
|
|
return BaseSerializer.prototype.serialize.call(this, object, request);
|
2017-01-02 21:49:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
let {user} = RestSerializer.prototype.serialize.call(this, object, request);
|
|
|
|
|
|
|
|
if (object.postCount) {
|
|
|
|
let posts = object.posts.models.length;
|
|
|
|
|
|
|
|
user.count = {posts};
|
|
|
|
}
|
|
|
|
|
|
|
|
return {users: [user]};
|
|
|
|
}
|
|
|
|
});
|