mirror of
https://git.sr.ht/~roxwize/mipilin
synced 2025-05-07 22:13:07 +00:00
done for today...
Signed-off-by: roxwize <rae@roxwize.xyz>
This commit is contained in:
parent
d173e6ea73
commit
453a143bfa
5 changed files with 53 additions and 7 deletions
|
@ -1,6 +1,6 @@
|
|||
import { NodePgDatabase } from "drizzle-orm/node-postgres";
|
||||
import { Express } from "express";
|
||||
import { createInviteCode, render, UserStatus } from "./util.js";
|
||||
import { createInviteCode, render, render404, UserStatus } from "./util.js";
|
||||
import { inviteCodes, users } from "../db/schema.js";
|
||||
import { and, count, desc, eq, sql } from "drizzle-orm";
|
||||
import dayjs from "dayjs";
|
||||
|
@ -13,7 +13,7 @@ export default function (app: Express, db: NodePgDatabase) {
|
|||
!req.session["loggedIn"] ||
|
||||
!(req.session["status"] & UserStatus.MODERATOR)
|
||||
) {
|
||||
res.redirect("/");
|
||||
render404(db, res, req);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ import {
|
|||
} from "../db/schema.js";
|
||||
import { and, count, desc, eq, sql } from "drizzle-orm";
|
||||
import dayjs from "dayjs";
|
||||
import { getMoods, render, render404 } from "./util.js";
|
||||
import { getMoods, render, render404, UserStatus } from "./util.js";
|
||||
|
||||
export default async function (app: Express, db: NodePgDatabase) {
|
||||
const { moods, moodsSorted } = await getMoods();
|
||||
|
@ -155,19 +155,54 @@ export default async function (app: Express, db: NodePgDatabase) {
|
|||
render(db, "journal", "your journal", res, req);
|
||||
});
|
||||
app.get("/journal/:id", async (req, res) => {
|
||||
const entry = (
|
||||
const entry: {
|
||||
uname: string,
|
||||
title: string,
|
||||
content: string,
|
||||
moodChange: number,
|
||||
moodString?: string,
|
||||
date: Date,
|
||||
visibility: number
|
||||
} = (
|
||||
await db
|
||||
.select({
|
||||
uname: users.name,
|
||||
title: journalEntries.title,
|
||||
content: journalEntries.entry,
|
||||
date: journalEntries.date
|
||||
moodChange: journalEntries.moodChange,
|
||||
date: journalEntries.date,
|
||||
visibility: journalEntries.visibility
|
||||
})
|
||||
.from(journalEntries)
|
||||
.where(eq(journalEntries.id, parseInt(req.params.id)))
|
||||
.leftJoin(users, eq(journalEntries.user, users.id))
|
||||
)[0];
|
||||
if (!entry) {
|
||||
|
||||
//? put into util function?
|
||||
//? also GOD
|
||||
switch (entry.moodChange) {
|
||||
case -2:
|
||||
entry.moodString = "much worse"
|
||||
break;
|
||||
case -1:
|
||||
entry.moodString = "worse";
|
||||
break;
|
||||
default:
|
||||
case 0:
|
||||
entry.moodString = "about the same";
|
||||
break;
|
||||
case 1:
|
||||
entry.moodString = "better";
|
||||
break;
|
||||
case 2:
|
||||
entry.moodString = "much better";
|
||||
break;
|
||||
}
|
||||
|
||||
if (
|
||||
!entry ||
|
||||
(entry.visibility === 0 && entry.uname !== req.session["user"] && !(req.session["status"] & UserStatus.MODERATOR))
|
||||
) {
|
||||
render404(db, res, req);
|
||||
return;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue