mirror of
https://github.com/Akif9748/akf-forum.git
synced 2024-11-22 20:10:40 +03:00
HOTFIX FOR MESSAGE API
This commit is contained in:
parent
a09a74d370
commit
a95015a4b5
4 changed files with 8 additions and 8 deletions
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
||||
})
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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>
|
||||
|
|
Loading…
Reference in a new issue