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) => { app.post("/", async (req, res) => {
const { title, content } = req.body; const { title, content, category } = req.body;
return console.log(req.body)
if (!content || !title) return res.error(400, "Missing content/title in request body."); if (!content || !title) return res.error(400, "Missing content/title in request body.");
const { user } = req; const { user } = req;
const thread = await new ThreadModel({ title, author: user }).takeId() 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() const message = await new MessageModel({ content, author: user, threadID: thread.id }).takeId()
await thread.push(message.id).save(); await thread.push(message.id).save();
await message.save(); await message.save();

View file

@ -14,9 +14,11 @@
<input name="title" class="input"></input> <input name="title" class="input"></input>
<h2 class="title" style="align-self: baseline;">Content:</h2> <h2 class="title" style="align-self: baseline;">Content:</h2>
<textarea rows="4" cols="50" name="content" class="input"></textarea> <textarea rows="4" cols="50" name="content" class="input"></textarea>
<h2 class="title" style="align-self: baseline;">Category:</h2>
<select name="category"> <select name="category">
<% for (const category of categories) { %> <% for (const category of categories) { %>
<option name="<%= category.id %>" value="<%= category.name %>"><%= category.name %></option> <option value="<%= category.id %>"><%= category.name %></option>
<% } %> <% } %>
</select> </select>
@ -35,7 +37,7 @@
const response = await request("/api/threads/", "POST", { const response = await request("/api/threads/", "POST", {
title: data.get("title"), title: data.get("title"),
content: data.get("content"), content: data.get("content"),
categord: data.get("category") category: data.get("category")
}); });