From 0b3a1787157440da540fd4bf8917f178128784a1 Mon Sep 17 00:00:00 2001 From: leca Date: Fri, 17 Nov 2023 09:16:05 +0300 Subject: [PATCH] changed /api/getPosts --- src/index.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/index.js b/src/index.js index 1efa569..10f7af6 100644 --- a/src/index.js +++ b/src/index.js @@ -69,8 +69,8 @@ app.post('/api/uploadMedia', async (req, res) => { app.get('/api/getPosts/:boardId/:threadId', async (req, res) => { posts = []; - (await db.query('SELECT post_id FROM posts WHERE board_id = $1 AND thread_id = $2', [req.params.boardId, req.params.threadId])).rows - .forEach((post) => posts.push(post.post_id)) + (await db.query('SELECT post_id, content, timestamp, options FROM posts WHERE board_id = $1 AND thread_id = $2', [req.params.boardId, req.params.threadId])).rows + .forEach((post) => posts.push(post)) res.setHeader('Content-Type', 'application/json'); res.end(JSON.stringify(posts)); @@ -133,12 +133,10 @@ app.post('/api/createThread', async (req, res) => { await db.query('INSERT INTO posts (board_id, thread_id, post_id, content, is_root, timestamp, user_ip) VALUES($1, $2, $3, $4, $5, NOW(), $6)', [boardId, threadId, postId, content, true, req.socket.remoteAddress]); await db.query('INSERT INTO threads (board_id, thread_id, thread_name, posts_ids, is_locked, is_pinned, options) VALUES ($1, $2, $3, $4, $5, $6, $7)', [boardId, 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}`); }); 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]; threads = []; (await db.query('SELECT thread_id FROM threads WHERE board_id = $1', [req.params.boardId])).rows .forEach((thread) => threads.push(thread.thread_id))