mirror of
https://github.com/Tony0410/quietthanks.git
synced 2026-05-25 05:41:38 +08:00
Add multiple entries per day, user management, reminders, and AI reflections
- Multiple entries per day: Home page now starts fresh, Save & New button - Admin user management: Add/delete users, reset passwords, toggle admin - Daily reminders: Browser notifications at configurable time - AI reflections: Generate insights from entries using Claude API - Remove cloud sync placeholder (already have user accounts) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
77
src/app/api/settings/route.ts
Normal file
77
src/app/api/settings/route.ts
Normal file
@@ -0,0 +1,77 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { db, schema } from "@/lib/db";
|
||||
import { getSession } from "@/lib/auth";
|
||||
import { eq } from "drizzle-orm";
|
||||
|
||||
// GET /api/settings - Get current user settings
|
||||
export async function GET() {
|
||||
const user = await getSession();
|
||||
if (!user) {
|
||||
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
|
||||
}
|
||||
|
||||
try {
|
||||
const users = await db
|
||||
.select({
|
||||
reminderEnabled: schema.users.reminderEnabled,
|
||||
reminderTime: schema.users.reminderTime,
|
||||
hasLlmKey: schema.users.llmApiKey,
|
||||
})
|
||||
.from(schema.users)
|
||||
.where(eq(schema.users.id, user.id))
|
||||
.limit(1);
|
||||
|
||||
if (users.length === 0) {
|
||||
return NextResponse.json({ error: "User not found" }, { status: 404 });
|
||||
}
|
||||
|
||||
return NextResponse.json({
|
||||
reminderEnabled: users[0].reminderEnabled === 1,
|
||||
reminderTime: users[0].reminderTime || "20:00",
|
||||
hasLlmKey: Boolean(users[0].hasLlmKey),
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("Failed to fetch settings:", error);
|
||||
return NextResponse.json({ error: "Failed to fetch settings" }, { status: 500 });
|
||||
}
|
||||
}
|
||||
|
||||
// PATCH /api/settings - Update user settings
|
||||
export async function PATCH(request: NextRequest) {
|
||||
const user = await getSession();
|
||||
if (!user) {
|
||||
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
|
||||
}
|
||||
|
||||
try {
|
||||
const body = await request.json();
|
||||
const updates: Record<string, unknown> = {};
|
||||
|
||||
if (typeof body.reminderEnabled === "boolean") {
|
||||
updates.reminderEnabled = body.reminderEnabled ? 1 : 0;
|
||||
}
|
||||
|
||||
if (typeof body.reminderTime === "string") {
|
||||
updates.reminderTime = body.reminderTime;
|
||||
}
|
||||
|
||||
if (typeof body.llmApiKey === "string") {
|
||||
// Store the API key (in production, encrypt this)
|
||||
updates.llmApiKey = body.llmApiKey || null;
|
||||
}
|
||||
|
||||
if (Object.keys(updates).length === 0) {
|
||||
return NextResponse.json({ error: "No updates provided" }, { status: 400 });
|
||||
}
|
||||
|
||||
await db
|
||||
.update(schema.users)
|
||||
.set(updates)
|
||||
.where(eq(schema.users.id, user.id));
|
||||
|
||||
return NextResponse.json({ success: true });
|
||||
} catch (error) {
|
||||
console.error("Failed to update settings:", error);
|
||||
return NextResponse.json({ error: "Failed to update settings" }, { status: 500 });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user