From b660217da4f41e19a9ad710f1bcde586f574e90e Mon Sep 17 00:00:00 2001 From: Akif9748 Date: Fri, 9 Sep 2022 20:55:05 +0300 Subject: [PATCH] Added category --- routes/api/routes/threads.js | 6 ++++-- views/create_thread.ejs | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/routes/api/routes/threads.js b/routes/api/routes/threads.js index 2895605..3f7527e 100644 --- a/routes/api/routes/threads.js +++ b/routes/api/routes/threads.js @@ -38,12 +38,14 @@ app.get("/:id/messages/", async (req, res) => { app.post("/", async (req, res) => { - const { title, content } = req.body; -return console.log(req.body) + const { title, content, category } = req.body; + if (!content || !title) return res.error(400, "Missing content/title in request body."); const { user } = req; const thread = await new ThreadModel({ title, author: user }).takeId() + if (category) + thread.categoryID = category; const message = await new MessageModel({ content, author: user, threadID: thread.id }).takeId() await thread.push(message.id).save(); await message.save(); diff --git a/views/create_thread.ejs b/views/create_thread.ejs index 54b3d6b..6a01f12 100644 --- a/views/create_thread.ejs +++ b/views/create_thread.ejs @@ -14,9 +14,11 @@

Content:

+

Category:

+ @@ -35,7 +37,7 @@ const response = await request("/api/threads/", "POST", { title: data.get("title"), content: data.get("content"), - categord: data.get("category") + category: data.get("category") });