first commit

This commit is contained in:
Michael Dong
2026-02-05 11:24:40 +08:00
commit a98e12f286
144 changed files with 26459 additions and 0 deletions

53
backend/src/routes/me.ts Normal file
View File

@@ -0,0 +1,53 @@
import { Router } from "express";
import { z } from "zod";
import { prisma } from "../db";
import { requireAuth, type AuthRequest } from "../middleware/auth";
export const meRouter = Router();
meRouter.use(requireAuth);
meRouter.get("/", async (req: AuthRequest, res) => {
const user = await prisma.user.findUnique({
where: { id: req.userId! },
select: {
id: true,
username: true,
avatar: true,
timezone: true,
barkUrl: true,
inappEnabled: true,
barkEnabled: true,
},
});
return res.json(user);
});
const settingsSchema = z.object({
avatar: z.string().url().optional().nullable(),
timezone: z.string().optional(),
barkUrl: z.string().url().optional().nullable(),
inappEnabled: z.boolean().optional(),
barkEnabled: z.boolean().optional(),
});
meRouter.put("/settings", async (req: AuthRequest, res) => {
const parsed = settingsSchema.safeParse(req.body);
if (!parsed.success) {
return res.status(400).json({ error: "Invalid payload" });
}
const user = await prisma.user.update({
where: { id: req.userId! },
data: parsed.data,
select: {
id: true,
username: true,
avatar: true,
timezone: true,
barkUrl: true,
inappEnabled: true,
barkEnabled: true,
},
});
return res.json(user);
});