mirror of
https://git.sr.ht/~roxwize/mipilin
synced 2025-05-07 22:13:07 +00:00
joo can now delete mood updats
Signed-off-by: roxwize <rae@roxwize.xyz>
This commit is contained in:
parent
0ecc741a98
commit
8e3ae72ae7
9 changed files with 78 additions and 13 deletions
|
@ -55,6 +55,7 @@ export default async function (app: Express, db: NodePgDatabase) {
|
|||
const recentUpdates = (
|
||||
await db
|
||||
.select({
|
||||
id: updates.id,
|
||||
user: users.name,
|
||||
mood: updates.mood,
|
||||
desc: updates.description,
|
||||
|
@ -73,6 +74,7 @@ export default async function (app: Express, db: NodePgDatabase) {
|
|||
.limit(25)
|
||||
).map((e) => {
|
||||
return {
|
||||
id: e.id,
|
||||
user: e.user,
|
||||
mood: moods[e.mood],
|
||||
desc: e.desc,
|
||||
|
@ -131,7 +133,7 @@ export default async function (app: Express, db: NodePgDatabase) {
|
|||
feed: []
|
||||
});
|
||||
});
|
||||
app.post("/update/mood", async (req, res) => {
|
||||
app.post("/mood/update", async (req, res) => {
|
||||
if (!req.session["loggedIn"]) {
|
||||
res.redirect("/login");
|
||||
return;
|
||||
|
@ -174,6 +176,29 @@ export default async function (app: Express, db: NodePgDatabase) {
|
|||
req.flash("success", "Mood updated!");
|
||||
res.redirect("/dashboard");
|
||||
});
|
||||
app.post("/mood/delete", async (req, res) => {
|
||||
const u = parseInt(req.body.upd);
|
||||
if (!req.session["loggedIn"] || !req.body.upd || isNaN(u)) {
|
||||
render404(db, res, req);
|
||||
return;
|
||||
}
|
||||
|
||||
const { user } = (await db.select({user: updates.user}).from(updates).where(eq(updates.id, u)).limit(1))[0];
|
||||
if (!user || (user !== req.session["uid"] && !(req.session["status"] & UserStatus.MODERATOR))) {
|
||||
render404(db, res, req);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!confirm(db, res, req, "/dashboard")) {
|
||||
return;
|
||||
}
|
||||
await db.delete(updates).where(eq(updates.id, u));
|
||||
|
||||
req.flash("success", "Update deleted ;w;");
|
||||
//! TODO: do we have to do it this way????? confirm() is fucking this up
|
||||
// also for the API using localstorage here from then would probably be a better idea
|
||||
res.redirect(req.session["back"]);
|
||||
});
|
||||
|
||||
// JOURNAL
|
||||
app.get("/journal", async (req, res) => {
|
||||
|
@ -285,18 +310,17 @@ export default async function (app: Express, db: NodePgDatabase) {
|
|||
if (req.body.action === "edit") {
|
||||
// TODO!!
|
||||
} else if (req.body.action === "delete") {
|
||||
if (!req.body.confirm) {
|
||||
confirm(db, res, req);
|
||||
if (!confirm(db, res, req, `/journal/${req.params.id}`)) {
|
||||
return;
|
||||
}
|
||||
await db.delete(journalEntries).where(eq(journalEntries.id, id));
|
||||
req.flash("success", "Journal entry deleted ;w;");
|
||||
res.redirect("/");
|
||||
res.redirect(req.session["back"]);
|
||||
} else {
|
||||
render404(db, res, req);
|
||||
}
|
||||
});
|
||||
app.post("/update/journal", async (req, res) => {
|
||||
app.post("/journal/update", async (req, res) => {
|
||||
if (!req.session["loggedIn"]) {
|
||||
res.redirect("/login");
|
||||
return;
|
||||
|
|
|
@ -114,6 +114,7 @@ export default async function (app: Express, db: NodePgDatabase) {
|
|||
const userMoodFeed = (
|
||||
await db
|
||||
.select({
|
||||
id: updates.id,
|
||||
mood: updates.mood,
|
||||
date: updates.date,
|
||||
desc: updates.description
|
||||
|
@ -123,6 +124,7 @@ export default async function (app: Express, db: NodePgDatabase) {
|
|||
.orderBy(desc(updates.date))
|
||||
).map((e) => {
|
||||
return {
|
||||
id: e.id,
|
||||
user: user.name,
|
||||
mood: moods[e.mood],
|
||||
date: e.date,
|
||||
|
|
|
@ -136,9 +136,19 @@ export function journalMoodString(mood: number) {
|
|||
export function confirm(
|
||||
db: NodePgDatabase,
|
||||
res: Response,
|
||||
req: Request
|
||||
req: Request,
|
||||
defaultUrl = "/"
|
||||
) {
|
||||
render(db, "confirm", "Confirm action", res, req, { body: req.body, url: req.url });
|
||||
if (req.body.confirm === undefined) {
|
||||
req.session["back"] = req.get("Referrer") || defaultUrl;
|
||||
render(db, "confirm", "Confirm action", res, req, { body: req.body, url: req.url });
|
||||
} else if (req.body.confirm === "y") {
|
||||
return true;
|
||||
} else {
|
||||
//! dumb
|
||||
res.redirect(req.session["back"] || defaultUrl);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
const emailRegex = /^([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x22([^\x0d\x22\x5c\x80-\xff]|\x5c[\x00-\x7f])*\x22)(\x2e([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x22([^\x0d\x22\x5c\x80-\xff]|\x5c[\x00-\x7f])*\x22))*\x40([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x5b([^\x0d\x5b-\x5d\x80-\xff]|\x5c[\x00-\x7f])*\x5d)(\x2e([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x5b([^\x0d\x5b-\x5d\x80-\xff]|\x5c[\x00-\x7f])*\x5d))*$/i;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue