reply chain fixes, refactoring
This commit is contained in:
parent
f0782b0472
commit
93027bfd09
4 changed files with 42 additions and 43 deletions
|
@ -1,5 +1,6 @@
|
|||
import { Router } from "express";
|
||||
import { initDb } from "../db.js";
|
||||
import { replyIterator } from "../lib.js";
|
||||
const router = Router();
|
||||
let db = await initDb();
|
||||
|
||||
|
@ -42,28 +43,7 @@ router.get('/get/:type/:id/:num', async (req, res, next) => {
|
|||
childId: req.params.id
|
||||
})
|
||||
|
||||
//TODO: make iterator
|
||||
for (let reply of replies) {
|
||||
if (reply.childType == 'hub') {
|
||||
reply.comment = { type: reply.childType, id: reply.childId, content: `The ${reply.childId} hub.`, username: false, date: undefined };
|
||||
continue;
|
||||
} else if (reply.childType == 'users') {
|
||||
reply.comment = { type: reply.childType, id: reply.childId, content: `User ${reply.childId}'s wall.`, username: false, date: undefined };
|
||||
continue;
|
||||
}
|
||||
|
||||
let dat = await db.all('SELECT * FROM comment WHERE id = ?', [
|
||||
reply.childId
|
||||
]);
|
||||
|
||||
if (reply.childType != 'comment' || dat.length < 1) {
|
||||
reply.comment = 'fail';
|
||||
continue;
|
||||
}
|
||||
reply.comment = dat[0];
|
||||
reply.comment.type = reply.childType;
|
||||
//reply.comment.id = reply.childId;
|
||||
}
|
||||
replies = await replyIterator(replies,db);
|
||||
|
||||
let comment = replies.splice(0, 1)[0];
|
||||
replies = replies.filter(x => x.comment != 'fail');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue