Implemented board options
This commit is contained in:
parent
bf994540a1
commit
ad5fc689f9
30
src/index.js
30
src/index.js
|
@ -5,15 +5,16 @@ const dotenv = require('dotenv');
|
|||
const MemoryStore = require('memorystore')(session);
|
||||
const fs = require('fs');
|
||||
const bcrypt = require('bcryptjs');
|
||||
const fileupload = require('express-fileupload');
|
||||
// const fileupload = require('express-fileupload');
|
||||
|
||||
const app = express();
|
||||
|
||||
dotenv.config({ path: './web.env' });
|
||||
const default_board_settings = require('../default_board_settings.json');
|
||||
|
||||
const db = new Client({
|
||||
user: process.env.DB_USER,
|
||||
host: "db",
|
||||
host: process.env.DB_HOST,
|
||||
database: process.env.DB_NAME,
|
||||
password: process.env.DB_PASS,
|
||||
port: 5432
|
||||
|
@ -75,7 +76,20 @@ app.post('/api/post', async (req, res) => {
|
|||
});
|
||||
|
||||
app.post('/api/createThread', async (req, res) => {
|
||||
const { threadName, isLocked, isPinned } = req.body;
|
||||
let login, token
|
||||
const { boardId, threadName, isLocked, isPinned, content, options} = req.body;
|
||||
|
||||
try {
|
||||
let currentSession = req.session;
|
||||
token = currentSession.token;
|
||||
login = currentSession.login;
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
}
|
||||
|
||||
if (token != tokens[login]) return res.status(403).send("Невалидный токен");
|
||||
// if ()
|
||||
|
||||
});
|
||||
|
||||
app.get('/api/getBoards', async (req, res) => {
|
||||
|
@ -109,8 +123,9 @@ app.post('/api/login', async (req, res) => {
|
|||
});
|
||||
|
||||
app.post('/api/createBoard', async (req, res) => {
|
||||
const { boardId, boardTitle } = req.body;
|
||||
let login, token;
|
||||
let { boardId, boardTitle, options} = req.body;
|
||||
|
||||
try {
|
||||
let currentSession = req.session;
|
||||
token = currentSession.token;
|
||||
|
@ -119,7 +134,8 @@ app.post('/api/createBoard', async (req, res) => {
|
|||
console.log(err);
|
||||
}
|
||||
|
||||
// if (token != tokens[login] || !token) return res.status(403).send("Невалидный токен");
|
||||
if (token != tokens[login] || !token) return res.status(403).send("Невалидный токен");
|
||||
if (!boardId || !boardTitle) return res.status(400).send("Неверно сформирован запрос");
|
||||
|
||||
console.log(`Admin ${login} is creating new board: ${boardId}, ${boardTitle}`);
|
||||
|
||||
|
@ -128,7 +144,9 @@ app.post('/api/createBoard', async (req, res) => {
|
|||
if (boardTitle.length == 0 || boardTitle.length > 32) return res.status(401).send("Неверный размер имени борды");
|
||||
if (queryRes.rowCount > 0) return res.status(401).send("Такая борда уже существует.");
|
||||
|
||||
await db.query('INSERT INTO boards (board_id, board_name) VALUES ($1, $2)', [boardId, boardTitle]);
|
||||
if (!options) options = default_board_settings;
|
||||
|
||||
await db.query('INSERT INTO boards (board_id, board_name, options) VALUES ($1, $2, $3)', [boardId, boardTitle, options]);
|
||||
return res.status(200).send("Борда успешно создана");
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue