akf-forum/routes/messages.js

16 lines
453 B
JavaScript
Raw Normal View History

2022-08-11 00:38:44 +03:00
const { MessageModel } = require("../models");
2022-03-21 23:53:22 +03:00
const { Router } = require("express");
const app = Router();
2022-04-06 21:14:46 +03:00
app.get("/:id", async (req, res) => {
const message = await MessageModel.get(req.params.id);
2022-03-21 23:53:22 +03:00
2022-08-31 14:44:28 +03:00
if (!message || (message.deleted && !req.user?.admin)) return res.error( 404,
2022-08-29 16:16:44 +03:00
`We don't have any message with id ${req.params.id}.`);
2022-08-29 19:31:59 +03:00
res.redirect(`/threads/${message.threadID}?scroll=${message.id}`);
2022-03-21 23:53:22 +03:00
});
module.exports = app;