mirror of
https://github.com/Akif9748/akf-forum.git
synced 2024-11-01 03:25:04 +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";
|
import request from "./request.js";
|
||||||
|
|
||||||
window.edit_t = async function (id) {
|
window.edit_thread = async function (id) {
|
||||||
const title = prompt("Enter new title!");
|
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;
|
if (res.error) return;
|
||||||
alert(`Thread updated`);
|
alert(`Thread updated`);
|
||||||
document.getElementById("title").innerHTML = title;
|
document.getElementById("title").innerHTML = title;
|
||||||
|
@ -26,7 +26,7 @@ window.undelete_thread = async function (id) {
|
||||||
window.edit_message = async function (id) {
|
window.edit_message = async function (id) {
|
||||||
const content = prompt("Enter new content!");
|
const content = prompt("Enter new content!");
|
||||||
const res = await request(`/api/messages/${id}/`, "PATCH", { content });
|
const res = await request(`/api/messages/${id}/`, "PATCH", { content });
|
||||||
if (res.error) return;
|
if (res && res.error) return;
|
||||||
|
|
||||||
alert(`Message updated`);
|
alert(`Message updated`);
|
||||||
document.getElementById("message-" + id).querySelector(".content").innerHTML = content;
|
document.getElementById("message-" + id).querySelector(".content").innerHTML = content;
|
||||||
|
@ -42,7 +42,7 @@ window.undelete_message = async function (id) {
|
||||||
}
|
}
|
||||||
|
|
||||||
window.delete_message = async function (id) {
|
window.delete_message = async function (id) {
|
||||||
const response = await request(`/api/messages/${id}/`,"DELETE");
|
const response = await request(`/api/messages/${id}/`, "DELETE");
|
||||||
if (response.deleted) {
|
if (response.deleted) {
|
||||||
alert("Message deleted");
|
alert("Message deleted");
|
||||||
document.getElementById("dots-" + id).innerHTML = `
|
document.getElementById("dots-" + id).innerHTML = `
|
||||||
|
|
|
@ -6,7 +6,7 @@ const { Router } = require("express")
|
||||||
const app = Router();
|
const app = Router();
|
||||||
|
|
||||||
app.param("id", async (req, res, next, id) => {
|
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}.`);
|
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;
|
message.edited = true;
|
||||||
|
|
||||||
await message.save();
|
await message.save();
|
||||||
|
|
||||||
res.complate(message);
|
res.complate(message);
|
||||||
|
|
||||||
})
|
})
|
||||||
|
@ -101,7 +100,6 @@ app.delete("/:id/", async (req, res) => {
|
||||||
|
|
||||||
message.deleted = true;
|
message.deleted = true;
|
||||||
await message.save();
|
await message.save();
|
||||||
|
|
||||||
res.complate(message);
|
res.complate(message);
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
|
@ -72,6 +72,8 @@ app.delete("/:id/", async (req, res) => {
|
||||||
|
|
||||||
thread.deleted = true;
|
thread.deleted = true;
|
||||||
await thread.save();
|
await thread.save();
|
||||||
|
console.log(thread)
|
||||||
|
|
||||||
await MessageModel.updateMany({ threadID: thread.id }, { deleted: true });
|
await MessageModel.updateMany({ threadID: thread.id }, { deleted: true });
|
||||||
res.complate(thread);
|
res.complate(thread);
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
<% if (user && !thread.deleted){ %>
|
<% if (user && !thread.deleted){ %>
|
||||||
|
|
||||||
<a onclick="delete_thread('<%= thread.id %>')" class="btn-outline-primary" >DELETE</a>
|
<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) { %>
|
<% } else if (thread.deleted) { %>
|
||||||
<h3 style="display:inline;">This thread has been deleted</h3>
|
<h3 style="display:inline;">This thread has been deleted</h3>
|
||||||
<a onclick="undelete_thread('<%= thread.id %>')" class="btn-primary" >UNDELETE</a>
|
<a onclick="undelete_thread('<%= thread.id %>')" class="btn-primary" >UNDELETE</a>
|
||||||
|
|
Loading…
Reference in a new issue