Ghost/ghost/admin/mirage/serializers/post.js
Kevin Ansfield 9540b85a50 Fixed missing URLs in improved search results
ref https://linear.app/tryghost/issue/MOM-117

- `url` was missing in the results objects that we generate from the underlying search results
- updated service integration test with check for url presence
- updated service integration test to also run against the beta search
- added missing page factory to mirage setup
- updated mirage post serializer to include a uniquely identifiable URL for unpublished posts
2024-06-11 16:53:08 +01:00

43 lines
1.3 KiB
JavaScript

import BaseSerializer from './application';
import {camelize} from '@ember/string';
export default BaseSerializer.extend({
embed: true,
include(request) {
const queryIncludes = (request.queryParams.include || '').split(',').compact().map(camelize);
const includes = new Set(queryIncludes);
// embedded records that are included by default in the API
includes.add('tags');
includes.add('authors');
// clean up some things that mirage doesn't understand
includes.delete('authorsRoles');
includes.delete('countClicks');
includes.delete('postRevisionsAuthor');
includes.delete('tiers');
const result = Array.from(includes);
return result;
},
serialize(postModelOrCollection, request) {
const updatePost = (post) => {
if (post.status === 'published') {
post.update('url', `http://localhost:4200/${post.slug}/`);
} else {
post.update('url', `http://localhost:4200/p/${post.uuid}/`);
}
};
if (this.isModel(postModelOrCollection)) {
updatePost(postModelOrCollection);
} else {
postModelOrCollection.models.forEach(updatePost);
}
return BaseSerializer.prototype.serialize.call(this, postModelOrCollection, request);
}
});