Add unlike method

This commit is contained in:
2021-04-08 14:11:38 +02:00
parent bbb33e81db
commit 7c8ef2a013

View File

@@ -36,17 +36,15 @@ export default class PostsController {
} }
public async unlike ({params, response}: HttpContextContract) { public async unlike ({params, response}: HttpContextContract) {
let post = await Post.findBy('slug', params.slug) let post = await Post.findByOrFail('slug', params.slug)
if (post) { await post.merge({
await post.merge({ likes: post.likes--
likes: post.likes-- }).save()
}).save() return response.status(200).send({
return response.status(200).send({ status: 200,
status: 200, post
post })
})
}
} }
} }