use savePostData method

This commit is contained in:
srgooglo 2022-06-03 06:26:41 +02:00
parent ceb4bb9406
commit c3ec2845f1

View File

@ -56,7 +56,8 @@ export default class PostsController extends Controller {
}
postData.likes.push(user_id)
await postData.save()
await this.savePostData(postData)
global.wsInterface.io.emit(`post.like`, {
...postData.toObject(),
@ -77,7 +78,8 @@ export default class PostsController extends Controller {
const postData = await Post.findById(post_id)
postData.likes = postData.likes.filter(id => id !== user_id)
await postData.save()
await this.savePostData(postData)
global.wsInterface.io.emit(`post.unlike`, {
...postData.toObject(),
@ -131,6 +133,13 @@ export default class PostsController extends Controller {
}
}
savePostData = async (post) => {
await post.save()
global.wsInterface.io.emit(`post.dataUpdate`, post.toObject())
global.wsInterface.io.emit(`post.dataUpdate.${post._id}`, post.toObject())
}
get = {
"/feed": Schematized({
select: ["user_id"]