aboutsummaryrefslogtreecommitdiff
path: root/src/server.js
diff options
context:
space:
mode:
authorMark Powers <mark@marks.kitchen>2020-12-30 22:28:39 -0600
committerMark Powers <mark@marks.kitchen>2020-12-30 22:28:39 -0600
commit5137bb9b277fcd45327680166c9e39f26ec48c45 (patch)
treea6084de81b4e993d29b34cecf8bf664212fbf654 /src/server.js
parent572671a916335fbbe8766b37b683b8a585c49abd (diff)
Add like button to posts
Diffstat (limited to 'src/server.js')
-rw-r--r--src/server.js10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/server.js b/src/server.js
index d820cd7..cd76b5d 100644
--- a/src/server.js
+++ b/src/server.js
@@ -146,6 +146,15 @@ function setUpRoutes(models, jwtFunctions, database, templates) {
let body = templates["blog-single"]({posts, date});
res.status(200).send(body)
})
+ server.get('/post/like/:type/:id', async (req, res) => {
+ let type = req.params.type
+ let id = req.params.id
+ var post = await models.posts.findOne({
+ where: { type, id },
+ });
+ post.update({likes: post.likes+1})
+ res.redirect(`/post/${type}/${id}`);
+ })
server.get('/tags/:name', async (req, res) => {
const { name } = req.params;
const postsWithTag = await models.tags.findAll({ attributes: ["postId"], where: { text: name } })
@@ -258,6 +267,7 @@ function setUpRoutes(models, jwtFunctions, database, templates) {
const type = req.body.type
req.body.description = marked(req.body.description)
const newPost = await models.posts.create(req.body);
+ newPost.likes = 0
req.files.forEach(async (file) => {
await models.pictures.create({ "source": "uploads/" + file.filename, "postId": newPost.id });
console.log("uploaded ", file.path);