refactor: migrate to monorepo structure with Docker, PocketBase, and e2e tests
- Reorganize into apps/, packages/, docs/, e2e/, pocketbase/ directories - Add Dockerfiles for web, worker, and PocketBase services - Add docker-compose.yml for local orchestration - Add turbo.json for monorepo task management - Add Playwright e2e test infrastructure - Add PocketBase backend with migrations - Remove Vite/Next.js/ESLint/PostCSS config files - Update package.json with workspace dependencies - Add .env.example and .dockerignore
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import { withAuth } from '@/lib/auth';
|
||||
import { createPocketBaseClient } from '@/lib/pocketbase';
|
||||
|
||||
// GET /api/search — Cross-entity full-text search
|
||||
export const GET = withAuth(async (request: NextRequest, _user) => {
|
||||
const { searchParams } = new URL(request.url);
|
||||
const query = searchParams.get('q') || '';
|
||||
const types = searchParams.get('types')?.split(',') || ['tasks', 'habits', 'projects', 'notes', 'reports'];
|
||||
const limit = parseInt(searchParams.get('limit') || '10');
|
||||
|
||||
if (!query.trim()) {
|
||||
return NextResponse.json({ results: [] });
|
||||
}
|
||||
|
||||
// Escape double quotes in query to prevent filter injection
|
||||
const safeQuery = query.replace(/"/g, '\\"');
|
||||
|
||||
const pb = createPocketBaseClient();
|
||||
const results: Array<{ type: string; items: unknown[] }> = [];
|
||||
|
||||
for (const type of types) {
|
||||
try {
|
||||
let filter = '';
|
||||
|
||||
switch (type) {
|
||||
case 'tasks':
|
||||
filter = `title ~ "${safeQuery}" || description ~ "${safeQuery}"`;
|
||||
break;
|
||||
case 'habits':
|
||||
filter = `name ~ "${safeQuery}" || description ~ "${safeQuery}"`;
|
||||
break;
|
||||
case 'projects':
|
||||
filter = `name ~ "${safeQuery}" || description ~ "${safeQuery}"`;
|
||||
break;
|
||||
case 'notes':
|
||||
filter = `title ~ "${safeQuery}" || content ~ "${safeQuery}"`;
|
||||
break;
|
||||
case 'reports':
|
||||
filter = `title ~ "${safeQuery}" || content ~ "${safeQuery}"`;
|
||||
break;
|
||||
default:
|
||||
continue;
|
||||
}
|
||||
|
||||
const items = await pb.collection(type).getList(1, limit, { filter });
|
||||
results.push({ type, items: items.items });
|
||||
} catch {
|
||||
// Skip collections that fail (e.g. missing or inaccessible)
|
||||
}
|
||||
}
|
||||
|
||||
return NextResponse.json({ results });
|
||||
});
|
||||
Reference in New Issue
Block a user