mirror of
https://github.com/Tony0410/quietthanks.git
synced 2026-05-24 21:31:41 +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:
@@ -66,7 +66,7 @@ export async function GET(request: NextRequest) {
|
||||
}
|
||||
}
|
||||
|
||||
// POST /api/entries - Create or update today's entry
|
||||
// POST /api/entries - Create a new entry or update existing by id
|
||||
export async function POST(request: NextRequest) {
|
||||
const user = await getSession();
|
||||
if (!user) {
|
||||
@@ -75,31 +75,33 @@ export async function POST(request: NextRequest) {
|
||||
|
||||
try {
|
||||
const body: CreateEntryRequest = await request.json();
|
||||
const { date, text, mood, roughDay, tagNames } = body;
|
||||
const { id: existingId, date, text, mood, roughDay, tagNames } = body;
|
||||
|
||||
if (!date || !text) {
|
||||
return NextResponse.json({ error: "Date and text are required" }, { status: 400 });
|
||||
}
|
||||
|
||||
const now = Date.now();
|
||||
|
||||
// Check if entry exists for this date for this user
|
||||
const existing = await db
|
||||
.select()
|
||||
.from(schema.entries)
|
||||
.where(
|
||||
and(
|
||||
eq(schema.entries.userId, user.id),
|
||||
eq(schema.entries.date, date)
|
||||
)
|
||||
)
|
||||
.limit(1);
|
||||
|
||||
let entryId: string;
|
||||
|
||||
if (existing.length > 0) {
|
||||
// Update existing entry
|
||||
entryId = existing[0].id;
|
||||
if (existingId) {
|
||||
// Update existing entry - verify ownership
|
||||
const existing = await db
|
||||
.select()
|
||||
.from(schema.entries)
|
||||
.where(
|
||||
and(
|
||||
eq(schema.entries.id, existingId),
|
||||
eq(schema.entries.userId, user.id)
|
||||
)
|
||||
)
|
||||
.limit(1);
|
||||
|
||||
if (existing.length === 0) {
|
||||
return NextResponse.json({ error: "Entry not found" }, { status: 404 });
|
||||
}
|
||||
|
||||
entryId = existingId;
|
||||
await db
|
||||
.update(schema.entries)
|
||||
.set({
|
||||
|
||||
Reference in New Issue
Block a user