mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-22 18:31:57 +03:00
28 lines
743 B
JavaScript
28 lines
743 B
JavaScript
|
import BaseSerializer from './application';
|
||
|
import {RestSerializer} from 'ember-cli-mirage';
|
||
|
|
||
|
export default BaseSerializer.extend({
|
||
|
serialize(object, request) {
|
||
|
if (this.isCollection(object)) {
|
||
|
return BaseSerializer.prototype.serialize.apply(this, arguments);
|
||
|
}
|
||
|
|
||
|
let {user} = RestSerializer.prototype.serialize.call(this, object, request);
|
||
|
|
||
|
if (object.postCount) {
|
||
|
let posts = object.posts.models.length;
|
||
|
|
||
|
user.count = {posts};
|
||
|
}
|
||
|
|
||
|
let roles = BaseSerializer.prototype.serialize.call(this, object.roles, request);
|
||
|
let [role] = roles.roles;
|
||
|
|
||
|
if (role) {
|
||
|
user.roles = [role];
|
||
|
}
|
||
|
|
||
|
return {users: [user]};
|
||
|
}
|
||
|
});
|