Added category

This commit is contained in:
Akif9748 2022-09-09 20:55:05 +03:00
parent ef1b5bff37
commit b660217da4
2 changed files with 8 additions and 4 deletions

View File

@ -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();

View File

@ -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")
});