add notifs
This commit is contained in:
parent
8c00723e16
commit
729a7b8c56
9 changed files with 158 additions and 5 deletions
|
@ -1,4 +1,7 @@
|
|||
import { Router } from "express";
|
||||
import { initDb } from "../db.js";
|
||||
|
||||
let db = await initDb();
|
||||
const router = Router();
|
||||
|
||||
//todo: fix jank
|
||||
|
@ -38,7 +41,6 @@ router.get('/logout', (req, res, next) => {
|
|||
next();
|
||||
})
|
||||
|
||||
|
||||
router.get('/new', (req, res, next) => {
|
||||
res.ctx.mainPage = 'form'
|
||||
res.ctx.mainCtx = {
|
||||
|
@ -69,4 +71,30 @@ router.get('/new', (req, res, next) => {
|
|||
next();
|
||||
})
|
||||
|
||||
router.get('/messages', async (req, res, next) => {
|
||||
let {username, valid} = res.auth;
|
||||
|
||||
if (!valid) {
|
||||
next();
|
||||
return;
|
||||
}
|
||||
|
||||
let messages = await db.all('SELECT * FROM messages WHERE username = ? ORDER BY date DESC LIMIT ? OFFSET ?', [
|
||||
username,
|
||||
10,
|
||||
0
|
||||
]);
|
||||
|
||||
await db.run('UPDATE messages SET status = ? WHERE username = ?', [
|
||||
'read',
|
||||
username
|
||||
]);
|
||||
|
||||
res.ctx.mainPage = 'messages'
|
||||
res.ctx.mainCtx = {
|
||||
messages
|
||||
}
|
||||
next();
|
||||
})
|
||||
|
||||
export default router;
|
Loading…
Add table
Add a link
Reference in a new issue