added /api/getThreads/:boardId
This commit is contained in:
parent
a7f6899164
commit
f08823dc95
11
src/index.js
11
src/index.js
|
@ -100,6 +100,7 @@ app.post('/api/createThread', async (req, res) => {
|
||||||
|
|
||||||
const boardOptions = (await db.query('SELECT * FROM boards WHERE board_id = $1', [boardId])).rows[0].options
|
const boardOptions = (await db.query('SELECT * FROM boards WHERE board_id = $1', [boardId])).rows[0].options
|
||||||
let postId = (await db.query('SELECT nextval(pg_get_serial_sequence(\'posts\', \'post_id\'))')).rows[0].nextval;
|
let postId = (await db.query('SELECT nextval(pg_get_serial_sequence(\'posts\', \'post_id\'))')).rows[0].nextval;
|
||||||
|
let threadId = (await db.query('SELECT nextval(pg_get_serial_sequence(\'threads\', \'thread_id\'))')).rows[0].nextval;
|
||||||
|
|
||||||
let validateResults = validateThread(threadTitle, isLocked,
|
let validateResults = validateThread(threadTitle, isLocked,
|
||||||
isPinned, content, options,
|
isPinned, content, options,
|
||||||
|
@ -107,10 +108,18 @@ app.post('/api/createThread', async (req, res) => {
|
||||||
if (validateResults != "ok") return res.status(400).send(validateResults);
|
if (validateResults != "ok") return res.status(400).send(validateResults);
|
||||||
|
|
||||||
await db.query('INSERT INTO posts (post_id, content, is_root, timestamp, user_ip) VALUES($1, $2, $3, NOW(), $4)', [postId, content, true, req.socket.remoteAddress]);
|
await db.query('INSERT INTO posts (post_id, content, is_root, timestamp, user_ip) VALUES($1, $2, $3, NOW(), $4)', [postId, content, true, req.socket.remoteAddress]);
|
||||||
await db.query('INSERT INTO threads (thread_name, posts_ids, is_locked, is_pinned, options) VALUES ($1, $2, $3, $4, $5)', [threadTitle, [postId], isLocked, isPinned, options]);
|
await db.query('INSERT INTO threads (thread_id, thread_name, posts_ids, is_locked, is_pinned, options) VALUES ($1, $2, $3, $4, $5, $6)', [threadId, threadTitle, [postId], isLocked, isPinned, options]);
|
||||||
|
await db.query('UPDATE boards SET threads_ids = ARRAY_APPEND(threads_ids, $1) WHERE board_id = $2', [threadId, boardId]);
|
||||||
res.redirect(`/${boardId}/${postId}`);
|
res.redirect(`/${boardId}/${postId}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
app.get('/api/getThreads/:boardId', async (req, res) => {
|
||||||
|
let queryRes = (await db.query('SELECT * FROM boards WHERE board_id = $1', [req.params.boardId])).rows[0];
|
||||||
|
|
||||||
|
res.setHeader('Content-Type', 'application/json');
|
||||||
|
res.end(JSON.stringify(queryRes.threads_ids));
|
||||||
|
});
|
||||||
|
|
||||||
app.get('/api/getBoards', async (req, res) => {
|
app.get('/api/getBoards', async (req, res) => {
|
||||||
let queryRes = await db.query('SELECT * FROM boards');
|
let queryRes = await db.query('SELECT * FROM boards');
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue