mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-20 22:42:53 -05:00
e96ff3fa81
refs https://github.com/TryGhost/Team/issues/1664 - Added comment-like model - Added like endpoint - Added unlike endpoint - Added basic tests for liking and unliking comments - Added permissions for liking and unliking - Added migration for permissions
34 lines
837 B
JavaScript
34 lines
837 B
JavaScript
const ghostBookshelf = require('./base');
|
|
|
|
const CommentLike = ghostBookshelf.Model.extend({
|
|
tableName: 'comment_likes',
|
|
|
|
defaults: function defaults() {
|
|
return {};
|
|
},
|
|
|
|
comment() {
|
|
return this.belongsTo('Comment', 'comment_id');
|
|
},
|
|
|
|
member() {
|
|
return this.belongsTo('Member', 'member_id');
|
|
},
|
|
|
|
emitChange: function emitChange(event, options) {
|
|
const eventToTrigger = 'comment_like' + '.' + event;
|
|
ghostBookshelf.Model.prototype.emitChange.bind(this)(this, eventToTrigger, options);
|
|
},
|
|
|
|
onCreated: function onCreated(model, options) {
|
|
ghostBookshelf.Model.prototype.onCreated.apply(this, arguments);
|
|
|
|
model.emitChange('added', options);
|
|
}
|
|
}, {
|
|
|
|
});
|
|
|
|
module.exports = {
|
|
CommentLike: ghostBookshelf.model('CommentLike', CommentLike)
|
|
};
|