mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-10 02:54:15 +00:00
37 lines
709 B
JavaScript
Executable File
37 lines
709 B
JavaScript
Executable File
import { PostLike } from "@models"
|
|
|
|
export default async (payload) => {
|
|
let { post_id, user_id, to } = payload
|
|
|
|
let likeObj = await PostLike.findOne({
|
|
post_id,
|
|
user_id,
|
|
}).catch(() => false)
|
|
|
|
if (typeof to === "undefined") {
|
|
if (likeObj) {
|
|
to = false
|
|
} else {
|
|
to = true
|
|
}
|
|
}
|
|
|
|
if (to) {
|
|
likeObj = new PostLike({
|
|
post_id,
|
|
user_id,
|
|
})
|
|
|
|
await likeObj.save()
|
|
} else {
|
|
await PostLike.findByIdAndDelete(likeObj._id)
|
|
}
|
|
|
|
global.websocket_instance.io.emit(`post.${post_id}.likes.update`, {
|
|
to,
|
|
post_id,
|
|
user_id,
|
|
})
|
|
|
|
return likeObj
|
|
} |