HOTFIX FOR MESSAGE API

This commit is contained in:
Akif9748 2022-08-31 16:05:23 +03:00
parent a09a74d370
commit a95015a4b5
4 changed files with 8 additions and 8 deletions

View file

@ -1,8 +1,8 @@
import request from "./request.js";
window.edit_t = async function (id) {
window.edit_thread = async function (id) {
const title = prompt("Enter new title!");
const res = await request(`/api/threads/${id}/edit`, "PATCH", { title });
const res = await request(`/api/threads/${id}/`, "PATCH", { title });
if (res.error) return;
alert(`Thread updated`);
document.getElementById("title").innerHTML = title;
@ -26,7 +26,7 @@ window.undelete_thread = async function (id) {
window.edit_message = async function (id) {
const content = prompt("Enter new content!");
const res = await request(`/api/messages/${id}/`, "PATCH", { content });
if (res.error) return;
if (res && res.error) return;
alert(`Message updated`);
document.getElementById("message-" + id).querySelector(".content").innerHTML = content;

View file

@ -6,7 +6,7 @@ const { Router } = require("express")
const app = Router();
app.param("id", async (req, res, next, id) => {
req.message = await ThreadModel.get(id);
req.message = await MessageModel.get(id);
if (!req.message) return res.error(404, `We don't have any message with id ${id}.`);
@ -34,7 +34,6 @@ app.patch("/:id/", async (req, res) => {
message.edited = true;
await message.save();
res.complate(message);
})
@ -101,7 +100,6 @@ app.delete("/:id/", async (req, res) => {
message.deleted = true;
await message.save();
res.complate(message);
})

View file

@ -72,6 +72,8 @@ app.delete("/:id/", async (req, res) => {
thread.deleted = true;
await thread.save();
console.log(thread)
await MessageModel.updateMany({ threadID: thread.id }, { deleted: true });
res.complate(thread);

View file

@ -26,7 +26,7 @@
<% if (user && !thread.deleted){ %>
<a onclick="delete_thread('<%= thread.id %>')" class="btn-outline-primary" >DELETE</a>
<a onclick="edit_t('<%= thread.id %>')" class="btn-outline-primary" >EDIT</a>
<a onclick="edit_thread('<%= thread.id %>')" class="btn-outline-primary" >EDIT</a>
<% } else if (thread.deleted) { %>
<h3 style="display:inline;">This thread has been deleted</h3>
<a onclick="undelete_thread('<%= thread.id %>')" class="btn-primary" >UNDELETE</a>