Implement reminders system with full CRUD and background processors
- Reminders service: create, update, delete, complete, snooze, dismiss - List with filters (status, priority, assignee, entity, date range) - My/overdue/upcoming convenience endpoints - BullMQ processors: auto-follow-up creation (BR-060) and overdue notifications - Snooze with presets (1h, 4h, tomorrow, next week) and custom datetime - Un-snooze logic: snoozed reminders auto-revert to pending when snooze expires - UI: filterable list with my/all toggle, priority badges, overdue indicators - Permission-gated: view_own, view_all, create, assign_others - Entity linking: reminders can link to clients, interests, or berths Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,16 +1,5 @@
|
||||
import { ReminderList } from '@/components/reminders/reminder-list';
|
||||
|
||||
export default function RemindersPage() {
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<div>
|
||||
<h1 className="text-2xl font-bold text-foreground">Reminders</h1>
|
||||
<p className="text-muted-foreground">Manage tasks and follow-up reminders</p>
|
||||
</div>
|
||||
<div className="flex flex-col items-center justify-center rounded-lg border border-dashed p-12">
|
||||
<p className="text-lg font-medium text-muted-foreground">Coming in Layer 2</p>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
This feature will be implemented in the next phase.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
return <ReminderList />;
|
||||
}
|
||||
|
||||
21
src/app/api/v1/reminders/[id]/complete/route.ts
Normal file
21
src/app/api/v1/reminders/[id]/complete/route.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
|
||||
import { withAuth, withPermission } from '@/lib/api/helpers';
|
||||
import { completeReminder } from '@/lib/services/reminders.service';
|
||||
import { errorResponse } from '@/lib/errors';
|
||||
|
||||
export const POST = withAuth(
|
||||
withPermission('reminders', 'edit_own', async (_req, ctx, params) => {
|
||||
try {
|
||||
const data = await completeReminder(params.id!, ctx.portId, {
|
||||
userId: ctx.userId,
|
||||
portId: ctx.portId,
|
||||
ipAddress: ctx.ipAddress,
|
||||
userAgent: ctx.userAgent,
|
||||
});
|
||||
return NextResponse.json({ data });
|
||||
} catch (error) {
|
||||
return errorResponse(error);
|
||||
}
|
||||
}),
|
||||
);
|
||||
21
src/app/api/v1/reminders/[id]/dismiss/route.ts
Normal file
21
src/app/api/v1/reminders/[id]/dismiss/route.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
|
||||
import { withAuth, withPermission } from '@/lib/api/helpers';
|
||||
import { dismissReminder } from '@/lib/services/reminders.service';
|
||||
import { errorResponse } from '@/lib/errors';
|
||||
|
||||
export const POST = withAuth(
|
||||
withPermission('reminders', 'edit_own', async (_req, ctx, params) => {
|
||||
try {
|
||||
const data = await dismissReminder(params.id!, ctx.portId, {
|
||||
userId: ctx.userId,
|
||||
portId: ctx.portId,
|
||||
ipAddress: ctx.ipAddress,
|
||||
userAgent: ctx.userAgent,
|
||||
});
|
||||
return NextResponse.json({ data });
|
||||
} catch (error) {
|
||||
return errorResponse(error);
|
||||
}
|
||||
}),
|
||||
);
|
||||
51
src/app/api/v1/reminders/[id]/route.ts
Normal file
51
src/app/api/v1/reminders/[id]/route.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
|
||||
import { withAuth, withPermission } from '@/lib/api/helpers';
|
||||
import { parseBody } from '@/lib/api/route-helpers';
|
||||
import { getReminder, updateReminder, deleteReminder } from '@/lib/services/reminders.service';
|
||||
import { updateReminderSchema } from '@/lib/validators/reminders';
|
||||
import { errorResponse } from '@/lib/errors';
|
||||
|
||||
export const GET = withAuth(
|
||||
withPermission('reminders', 'view_own', async (_req, ctx, params) => {
|
||||
try {
|
||||
const data = await getReminder(params.id!, ctx.portId);
|
||||
return NextResponse.json({ data });
|
||||
} catch (error) {
|
||||
return errorResponse(error);
|
||||
}
|
||||
}),
|
||||
);
|
||||
|
||||
export const PATCH = withAuth(
|
||||
withPermission('reminders', 'edit_own', async (req, ctx, params) => {
|
||||
try {
|
||||
const body = await parseBody(req, updateReminderSchema);
|
||||
const data = await updateReminder(params.id!, ctx.portId, body, {
|
||||
userId: ctx.userId,
|
||||
portId: ctx.portId,
|
||||
ipAddress: ctx.ipAddress,
|
||||
userAgent: ctx.userAgent,
|
||||
});
|
||||
return NextResponse.json({ data });
|
||||
} catch (error) {
|
||||
return errorResponse(error);
|
||||
}
|
||||
}),
|
||||
);
|
||||
|
||||
export const DELETE = withAuth(
|
||||
withPermission('reminders', 'edit_own', async (_req, ctx, params) => {
|
||||
try {
|
||||
await deleteReminder(params.id!, ctx.portId, {
|
||||
userId: ctx.userId,
|
||||
portId: ctx.portId,
|
||||
ipAddress: ctx.ipAddress,
|
||||
userAgent: ctx.userAgent,
|
||||
});
|
||||
return NextResponse.json({ success: true });
|
||||
} catch (error) {
|
||||
return errorResponse(error);
|
||||
}
|
||||
}),
|
||||
);
|
||||
24
src/app/api/v1/reminders/[id]/snooze/route.ts
Normal file
24
src/app/api/v1/reminders/[id]/snooze/route.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
|
||||
import { withAuth, withPermission } from '@/lib/api/helpers';
|
||||
import { parseBody } from '@/lib/api/route-helpers';
|
||||
import { snoozeReminder } from '@/lib/services/reminders.service';
|
||||
import { snoozeReminderSchema } from '@/lib/validators/reminders';
|
||||
import { errorResponse } from '@/lib/errors';
|
||||
|
||||
export const POST = withAuth(
|
||||
withPermission('reminders', 'edit_own', async (req, ctx, params) => {
|
||||
try {
|
||||
const body = await parseBody(req, snoozeReminderSchema);
|
||||
const data = await snoozeReminder(params.id!, ctx.portId, body, {
|
||||
userId: ctx.userId,
|
||||
portId: ctx.portId,
|
||||
ipAddress: ctx.ipAddress,
|
||||
userAgent: ctx.userAgent,
|
||||
});
|
||||
return NextResponse.json({ data });
|
||||
} catch (error) {
|
||||
return errorResponse(error);
|
||||
}
|
||||
}),
|
||||
);
|
||||
16
src/app/api/v1/reminders/my/route.ts
Normal file
16
src/app/api/v1/reminders/my/route.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
|
||||
import { withAuth, withPermission } from '@/lib/api/helpers';
|
||||
import { getMyReminders } from '@/lib/services/reminders.service';
|
||||
import { errorResponse } from '@/lib/errors';
|
||||
|
||||
export const GET = withAuth(
|
||||
withPermission('reminders', 'view_own', async (_req, ctx) => {
|
||||
try {
|
||||
const data = await getMyReminders(ctx.userId, ctx.portId);
|
||||
return NextResponse.json({ data });
|
||||
} catch (error) {
|
||||
return errorResponse(error);
|
||||
}
|
||||
}),
|
||||
);
|
||||
16
src/app/api/v1/reminders/overdue/route.ts
Normal file
16
src/app/api/v1/reminders/overdue/route.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
|
||||
import { withAuth, withPermission } from '@/lib/api/helpers';
|
||||
import { getOverdueReminders } from '@/lib/services/reminders.service';
|
||||
import { errorResponse } from '@/lib/errors';
|
||||
|
||||
export const GET = withAuth(
|
||||
withPermission('reminders', 'view_all', async (_req, ctx) => {
|
||||
try {
|
||||
const data = await getOverdueReminders(ctx.portId);
|
||||
return NextResponse.json({ data });
|
||||
} catch (error) {
|
||||
return errorResponse(error);
|
||||
}
|
||||
}),
|
||||
);
|
||||
50
src/app/api/v1/reminders/route.ts
Normal file
50
src/app/api/v1/reminders/route.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
|
||||
import { withAuth, withPermission } from '@/lib/api/helpers';
|
||||
import { parseBody, parseQuery } from '@/lib/api/route-helpers';
|
||||
import { listReminders, createReminder } from '@/lib/services/reminders.service';
|
||||
import { reminderListQuerySchema, createReminderSchema } from '@/lib/validators/reminders';
|
||||
import { errorResponse } from '@/lib/errors';
|
||||
|
||||
export const GET = withAuth(
|
||||
withPermission('reminders', 'view_own', async (req, ctx) => {
|
||||
try {
|
||||
const query = parseQuery(req, reminderListQuerySchema);
|
||||
const result = await listReminders(ctx.portId, query);
|
||||
return NextResponse.json(result);
|
||||
} catch (error) {
|
||||
return errorResponse(error);
|
||||
}
|
||||
}),
|
||||
);
|
||||
|
||||
export const POST = withAuth(
|
||||
withPermission('reminders', 'create', async (req, ctx) => {
|
||||
try {
|
||||
const body = await parseBody(req, createReminderSchema);
|
||||
|
||||
// Check assign_others permission if assigning to someone else
|
||||
if (body.assignedTo && body.assignedTo !== ctx.userId) {
|
||||
if (!ctx.isSuperAdmin) {
|
||||
const perms = ctx.permissions?.reminders;
|
||||
if (!perms?.assign_others) {
|
||||
return NextResponse.json(
|
||||
{ error: 'Cannot assign reminders to other users' },
|
||||
{ status: 403 },
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const data = await createReminder(ctx.portId, body, {
|
||||
userId: ctx.userId,
|
||||
portId: ctx.portId,
|
||||
ipAddress: ctx.ipAddress,
|
||||
userAgent: ctx.userAgent,
|
||||
});
|
||||
return NextResponse.json({ data }, { status: 201 });
|
||||
} catch (error) {
|
||||
return errorResponse(error);
|
||||
}
|
||||
}),
|
||||
);
|
||||
16
src/app/api/v1/reminders/upcoming/route.ts
Normal file
16
src/app/api/v1/reminders/upcoming/route.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
|
||||
import { withAuth, withPermission } from '@/lib/api/helpers';
|
||||
import { getUpcomingReminders } from '@/lib/services/reminders.service';
|
||||
import { errorResponse } from '@/lib/errors';
|
||||
|
||||
export const GET = withAuth(
|
||||
withPermission('reminders', 'view_own', async (_req, ctx) => {
|
||||
try {
|
||||
const data = await getUpcomingReminders(ctx.portId);
|
||||
return NextResponse.json({ data });
|
||||
} catch (error) {
|
||||
return errorResponse(error);
|
||||
}
|
||||
}),
|
||||
);
|
||||
Reference in New Issue
Block a user