mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-05 18:34:39 +03:00
Merge pull request #2634 from alarobric/feature/2608AuthorRelation
Post API response to use author not author_id
This commit is contained in:
commit
149a793e28
@ -211,6 +211,15 @@ Post = ghostBookshelf.Model.extend({
|
||||
|
||||
fields: function () {
|
||||
return this.morphMany(AppField, 'relatable');
|
||||
},
|
||||
|
||||
toJSON: function (options) {
|
||||
var attrs = ghostBookshelf.Model.prototype.toJSON.call(this, options);
|
||||
|
||||
attrs.author = attrs.author || attrs.author_id;
|
||||
delete attrs.author_id;
|
||||
|
||||
return attrs;
|
||||
}
|
||||
|
||||
}, {
|
||||
|
@ -73,6 +73,7 @@ describe('Post Model', function () {
|
||||
results.length.should.be.above(0);
|
||||
firstPost = results.models[0].toJSON();
|
||||
|
||||
should.not.exist(firstPost.author_id);
|
||||
firstPost.author.should.be.an.Object;
|
||||
firstPost.fields.should.be.an.Array;
|
||||
firstPost.author.name.should.equal(DataGenerator.Content.users[0].name);
|
||||
@ -89,6 +90,7 @@ describe('Post Model', function () {
|
||||
should.exist(result);
|
||||
firstPost = result.toJSON();
|
||||
|
||||
should.not.exist(firstPost.author_id);
|
||||
firstPost.author.should.be.an.Object;
|
||||
firstPost.fields.should.be.an.Array;
|
||||
firstPost.author.name.should.equal(testUtils.DataGenerator.Content.users[0].name);
|
||||
@ -142,6 +144,7 @@ describe('Post Model', function () {
|
||||
createdPost.get('created_at').should.be.above(new Date(0).getTime());
|
||||
createdPost.get('created_by').should.equal(1);
|
||||
createdPost.get('author_id').should.equal(1);
|
||||
createdPost.has('author').should.equal(false);
|
||||
createdPost.get('created_by').should.equal(createdPost.get('author_id'));
|
||||
createdPost.get('updated_at').should.be.above(new Date(0).getTime());
|
||||
createdPost.get('updated_by').should.equal(1);
|
||||
|
@ -8,7 +8,7 @@ var _ = require('lodash'),
|
||||
posts: ['posts', 'meta'],
|
||||
pagination: ['page', 'limit', 'pages', 'total', 'next', 'prev'],
|
||||
post: ['id', 'uuid', 'title', 'slug', 'markdown', 'html', 'meta_title', 'meta_description',
|
||||
'featured', 'image', 'status', 'language', 'author_id', 'created_at', 'created_by', 'updated_at',
|
||||
'featured', 'image', 'status', 'language', 'created_at', 'created_by', 'updated_at',
|
||||
'updated_by', 'published_at', 'published_by', 'page', 'author', 'tags', 'fields'],
|
||||
// TODO: remove databaseVersion, dbHash
|
||||
settings: ['databaseVersion', 'dbHash', 'title', 'description', 'email', 'logo', 'cover', 'defaultLang',
|
||||
|
Loading…
Reference in New Issue
Block a user