- 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
52 lines
1.8 KiB
TypeScript
52 lines
1.8 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 { updateCanvasSchema } from '@project-e/shared';
|
|
import { z } from 'zod';
|
|
|
|
type RouteContext = { params: Promise<{ id: string }> };
|
|
|
|
// GET /api/canvases/[id] — Get a single canvas
|
|
export const GET = withAuth<RouteContext>(async (request: NextRequest, _user, context) => {
|
|
const { id } = await context!.params;
|
|
|
|
const pb = createPocketBaseClient();
|
|
const canvas = await pb.collection('canvases').getOne(id);
|
|
|
|
return NextResponse.json(canvas);
|
|
});
|
|
|
|
// PATCH /api/canvases/[id] — Update a canvas
|
|
export const PATCH = withAuth<RouteContext>(async (request: NextRequest, _user, context) => {
|
|
try {
|
|
const { id } = await context!.params;
|
|
const body = await request.json();
|
|
const data = updateCanvasSchema.parse(body);
|
|
|
|
const pb = createPocketBaseClient();
|
|
const canvas = await pb.collection('canvases').update(id, data);
|
|
|
|
return NextResponse.json(canvas);
|
|
} catch (error) {
|
|
if (error instanceof z.ZodError) {
|
|
return createErrorResponse('VALIDATION_ERROR', 'Invalid input', 400, error.issues);
|
|
}
|
|
throw error;
|
|
}
|
|
});
|
|
|
|
// DELETE /api/canvases/[id] — Delete a canvas
|
|
export const DELETE = withAuth<RouteContext>(async (request: NextRequest, _user, context) => {
|
|
const { id } = await context!.params;
|
|
|
|
const pb = createPocketBaseClient();
|
|
await pb.collection('canvases').delete(id);
|
|
|
|
return new NextResponse(null, { status: 204 });
|
|
});
|