akf-forum/routes/post/createThread.js

14 lines
467 B
JavaScript
Raw Normal View History

2022-03-13 16:06:25 +03:00
const { User, Thread, Message } = require("../../classes/index");
2022-02-26 21:12:54 +03:00
module.exports = (req, res) => {
if (!req.session.loggedin) return res.redirect('/login');
2022-03-13 16:06:25 +03:00
const user = new User().getId(req.session.userid);
2022-02-26 21:12:54 +03:00
const info = req.body;
2022-03-13 16:06:25 +03:00
const thread = new Thread(info.title, user).takeId().write();
thread.push(new Message(info.content, user, thread).takeId().write().id)
thread.write();
2022-02-26 21:12:54 +03:00
res.redirect('/threads/' + thread.id);
}