0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-20 22:42:53 -05:00
ghost/core/server/models/comment-like.js
Simon Backx e96ff3fa81 Added comments API like and unlike actions
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
2022-07-12 10:24:02 +02:00

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)
};