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 @@ <input name="title" class="input"></input> <h2 class="title" style="align-self: baseline;">Content:</h2> <textarea rows="4" cols="50" name="content" class="input"></textarea> + <h2 class="title" style="align-self: baseline;">Category:</h2> + <select name="category"> <% for (const category of categories) { %> - <option name="<%= category.id %>" value="<%= category.name %>"><%= category.name %></option> + <option value="<%= category.id %>"><%= category.name %></option> <% } %> </select> @@ -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") });