mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-25 09:03:12 +03:00
Automatically update count.posts when serialising tags in mirage
no issue - add a new mirage serialiser for tags that updates the count.posts for each tag that gets serialised - better matches real API behaviour
This commit is contained in:
parent
ae0cb45d8c
commit
9abadd57c4
@ -14,8 +14,7 @@ export default Factory.extend({
|
||||
updatedAt: '2015-10-19T16:25:07.756Z',
|
||||
updatedBy: 1,
|
||||
count() {
|
||||
return {
|
||||
posts: 1
|
||||
};
|
||||
// this gets updated automatically by the tag serializer
|
||||
return {posts: 0};
|
||||
}
|
||||
});
|
||||
|
18
ghost/admin/mirage/serializers/tag.js
Normal file
18
ghost/admin/mirage/serializers/tag.js
Normal file
@ -0,0 +1,18 @@
|
||||
import BaseSerializer from './application';
|
||||
|
||||
export default BaseSerializer.extend({
|
||||
// make the tag.count.posts value dynamic
|
||||
serialize(tagModelOrCollection, request) {
|
||||
let updatePostCount = (tag) => {
|
||||
tag.update('count', {posts: tag.postIds.length});
|
||||
};
|
||||
|
||||
if (this.isModel(tagModelOrCollection)) {
|
||||
updatePostCount(tagModelOrCollection);
|
||||
} else {
|
||||
tagModelOrCollection.models.forEach(updatePostCount);
|
||||
}
|
||||
|
||||
return BaseSerializer.prototype.serialize.call(this, tagModelOrCollection, request);
|
||||
}
|
||||
});
|
Loading…
Reference in New Issue
Block a user