- Add reminders to Prisma schema (Reminder model, TaskReminder relation) - Add /api/reminders endpoint and cron send-reminders.ts script - Add reminder fields to NewTaskModal and EditTaskModal components - Fix reminder datetime serialization: use toISOString().slice(0,16) for UTC-safe YYYY-MM-DDTHH:mm format compatible with datetime-local inputs - Update Dockerfile to install tsx for cron container - Add AGENTS.md with project conventions - Update docker-compose.yml with cron service and build context
63 lines
1.6 KiB
TypeScript
63 lines
1.6 KiB
TypeScript
import { NextRequest, NextResponse } from 'next/server';
|
|
import prisma from '@/lib/db';
|
|
|
|
export async function GET(request: NextRequest) {
|
|
const { searchParams } = new URL(request.url);
|
|
const sent = searchParams.get('sent');
|
|
|
|
try {
|
|
const where: Record<string, unknown> = {};
|
|
if (sent !== null) where.sent = sent === 'true';
|
|
|
|
const reminders = await prisma.reminder.findMany({
|
|
where,
|
|
orderBy: [{ dueDate: 'asc' }],
|
|
});
|
|
|
|
return NextResponse.json(
|
|
reminders.map((r) => ({
|
|
...r,
|
|
dueDate: r.dueDate.toISOString(),
|
|
}))
|
|
);
|
|
} catch (error) {
|
|
console.error('Error fetching reminders:', error);
|
|
return NextResponse.json({ error: 'Failed to fetch reminders' }, { status: 500 });
|
|
}
|
|
}
|
|
|
|
export async function POST(request: NextRequest) {
|
|
let body;
|
|
try {
|
|
body = await request.json();
|
|
} catch {
|
|
return NextResponse.json({ error: 'Invalid JSON' }, { status: 400 });
|
|
}
|
|
|
|
const { message, dueDate } = body;
|
|
|
|
if (!message?.trim()) {
|
|
return NextResponse.json({ error: 'Message is required' }, { status: 400 });
|
|
}
|
|
if (!dueDate) {
|
|
return NextResponse.json({ error: 'dueDate is required' }, { status: 400 });
|
|
}
|
|
|
|
try {
|
|
const reminder = await prisma.reminder.create({
|
|
data: {
|
|
message: message.trim(),
|
|
dueDate: new Date(dueDate),
|
|
},
|
|
});
|
|
|
|
return NextResponse.json({
|
|
...reminder,
|
|
dueDate: reminder.dueDate.toISOString(),
|
|
});
|
|
} catch (error) {
|
|
console.error('Error creating reminder:', error);
|
|
return NextResponse.json({ error: 'Failed to create reminder' }, { status: 500 });
|
|
}
|
|
}
|