Ghost/ghost/admin/mirage/serializers/user.js
Kevin Ansfield c4c48d4104 Resolved ember-cli-mirage import deprecations
refs https://github.com/TryGhost/Admin/pull/2209

- `miragejs` has been extracted to a framework-independent library, the re-exports of `miragejs` elements in `ember-cli-mirage` have been deprecated making our test logs very noisy
- added `miragejs` as a top-level dependency
- updated all relevant imports to pull from `miragejs` instead of `ember-cli-mirage`
2022-03-08 11:32:01 +00:00

31 lines
756 B
JavaScript

import BaseSerializer from './application';
import {RestSerializer} from 'miragejs';
export default BaseSerializer.extend({
embed: true,
include(request) {
if (request.queryParams.include && request.queryParams.include.indexOf('roles') >= 0) {
return ['roles'];
}
return [];
},
serialize(object, request) {
if (this.isCollection(object)) {
return BaseSerializer.prototype.serialize.call(this, object, request);
}
let {user} = RestSerializer.prototype.serialize.call(this, object, request);
if (object.postCount) {
let posts = object.posts.models.length;
user.count = {posts};
}
return {users: [user]};
}
});