mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-09 10:34:17 +00:00
37 lines
711 B
JavaScript
Executable File
37 lines
711 B
JavaScript
Executable File
import { PostLike } from "@db_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.engine.ws.io.of("/").emit(`post.${post_id}.likes.update`, {
|
|
to,
|
|
post_id,
|
|
user_id,
|
|
})
|
|
|
|
return likeObj
|
|
} |