feat: added a comment section

This commit is contained in:
Smigz 2025-01-01 14:59:35 -05:00
parent 27840f3537
commit eda40eb113
11 changed files with 197 additions and 12 deletions

View file

@ -8,15 +8,43 @@ async function getAllMessages() {
});
}
async function getMessageById(id) {
return new Promise((resolve) => {
db.get("SELECT * FROM messages WHERE id = (?)", [id], async (err, rows) => {
resolve(rows);
});
});
}
async function insertMessage(msg) {
db.run("INSERT INTO MESSAGES (message, username, date) VALUES ($1, $2, $3)", [
db.run("INSERT INTO messages (message, username, date) VALUES ($1, $2, $3)", [
msg.message,
msg.username,
msg.date,
]);
}
async function getAllCommentsForMessage(msgId) {
return new Promise((resolve) => {
db.all(
"SELECT * FROM COMMENTS WHERE message_id = (?)",
[msgId],
async (err, rows) => resolve(rows),
);
});
}
async function insertComment(msgId, comment) {
db.run("INSERT INTO comments (comment, message_id) VALUES ($1, $2)", [
comment,
msgId,
]);
}
module.exports = {
getMessageById,
getAllMessages,
insertMessage,
getAllCommentsForMessage,
insertComment,
};