rittenhop-ghost/versions/5.94.2/core/server/models/post-revision.js

49 lines
1.3 KiB
JavaScript
Raw Normal View History

const ghostBookshelf = require('./base');
const _ = require('lodash');
const PostRevision = ghostBookshelf.Model.extend({
tableName: 'post_revisions',
author() {
return this.belongsTo('User', 'author_id');
},
permittedOptions(methodName) {
let options = ghostBookshelf.Model.permittedOptions.call(this, methodName);
const validOptions = {
findAll: ['filter', 'columns']
};
if (validOptions[methodName]) {
options = options.concat(validOptions[methodName]);
}
return options;
},
defaultRelations: function defaultRelations(methodName, options) {
if (['edit', 'add', 'destroy'].indexOf(methodName) !== -1) {
options.withRelated = _.union(['author'], options.withRelated || []);
}
return options;
},
orderDefaultRaw() {
return 'created_at_ts DESC';
},
toJSON(unfilteredOptions) {
const options = PostRevision.filterOptions(unfilteredOptions, 'toJSON');
const attrs = ghostBookshelf.Model.prototype.toJSON.call(this, options);
// We embed the full author object, so no need to send the author_id
delete attrs.author_id;
return attrs;
}
});
module.exports = {
PostRevision: ghostBookshelf.model('PostRevision', PostRevision)
};