2017-01-02 21:49:44 +03:00
|
|
|
import BaseSerializer from './application';
|
2022-03-08 14:32:01 +03:00
|
|
|
import {RestSerializer} from 'miragejs';
|
2017-01-02 21:49:44 +03:00
|
|
|
|
|
|
|
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]};
|
|
|
|
}
|
|
|
|
});
|