I have two services: posts
and comments
. Every post can have multiple comments. User 1 creates a post, user 2 creates a comment inside this post. Both users should be able to update, patch or delete the created comment. How do I correctly qualify both users to modify the comment created by user 2?
Posts model
{
userId: { type: DataTypes.INTEGER, allowNull: false },
text: { type: DataTypes.TEXT, allowNull: false },
};
posts.associate = function (models) {
posts.hasMany(models.comments, { onDelete: 'CASCADE' });
}
Comments model
{
userId: { type: DataTypes.INTEGER, allowNull: false },
postId: { type: DataTypes.INTEGER, allowNull: false },
text: { type: DataTypes.TEXT, allowNull: false },
};
comments.associate = function (models) {
comments.belongsTo(models.posts);
}
Posts can only be deleted by the post-creator, so setField
from the feathers-authentication-hooks
does a good job in this case. But how do I qualify the post-creator to manage comments inside his post?