- Rewrote Drizzle schema: 20 tables with enums, relations, indexes - Generated migration with DROP TABLE records (v1 EAV removal) - Added passkey auth routes (register/login) - Added requireWorkspaceAccess helper - Added seedDefaultData for Personal workspace + welcome note - Updated SSE endpoint for v2 entities + workspace_id filtering - Created recordActivity helper (insert + pg_notify) - Updated sidebar: Graph replaces Reports, removed Analytics - Updated command palette for v2 entities - Created AGENTS.md with locked contract - Created llm-wiki scaffold (5 stubs) - Added inline AGENT INSTRUCTION comments to all 50 API route files - Fixed globals.css border-border class conflict - Updated database.ts stub for v1 compatibility
59 lines
1.9 KiB
TypeScript
59 lines
1.9 KiB
TypeScript
// AGENT INSTRUCTION: After every write (INSERT/UPDATE/DELETE), you MUST:
|
|
// 1. Insert activity feed entry
|
|
// 2. Call pg.notify('project_e_events', JSON.stringify({ type, action, id, workspace_id }))
|
|
// See AGENTS.md for full rules.
|
|
|
|
import { NextRequest, NextResponse } from 'next/server';
|
|
import { withAuth, createErrorResponse } from '@/lib/auth';
|
|
import { createPocketBaseClient } from '@/lib/pocketbase';
|
|
import { createTaskSchema } from '@project-e/shared';
|
|
import { z } from 'zod';
|
|
|
|
// GET /api/tasks — List tasks with filtering, sorting, pagination
|
|
export const GET = withAuth(async (request: NextRequest, _user) => {
|
|
const { searchParams } = new URL(request.url);
|
|
const page = parseInt(searchParams.get('page') || '1');
|
|
const perPage = parseInt(searchParams.get('perPage') || '50');
|
|
const filter = searchParams.get('filter') || undefined;
|
|
const sort = searchParams.get('sort') || '-created';
|
|
|
|
const pb = createPocketBaseClient();
|
|
const result = await pb.collection('tasks').getList(page, perPage, {
|
|
...(filter ? { filter } : {}),
|
|
sort,
|
|
});
|
|
|
|
const response = NextResponse.json({
|
|
items: result.items,
|
|
totalItems: result.totalItems,
|
|
totalPages: result.totalPages,
|
|
page: result.page,
|
|
perPage: result.perPage,
|
|
});
|
|
|
|
response.headers.set(
|
|
'Cache-Control',
|
|
'private, max-age=60, stale-while-revalidate=300'
|
|
);
|
|
|
|
return response;
|
|
});
|
|
|
|
// POST /api/tasks — Create a task
|
|
export const POST = withAuth(async (request: NextRequest, _user) => {
|
|
try {
|
|
const body = await request.json();
|
|
const data = createTaskSchema.parse(body);
|
|
|
|
const pb = createPocketBaseClient();
|
|
const task = await pb.collection('tasks').create(data);
|
|
|
|
return NextResponse.json(task, { status: 201 });
|
|
} catch (error) {
|
|
if (error instanceof z.ZodError) {
|
|
return createErrorResponse('VALIDATION_ERROR', 'Invalid input', 400, error.issues);
|
|
}
|
|
throw error;
|
|
}
|
|
});
|