Complete rename of "swift" terminology to "cortex" across the codebase: Code Changes: - Rename directories: lib/swift → lib/cortex, components/swift → components/cortex - Rename API routes: /api/swift/* → /api/cortex/* - Rename page routes: /epd/swift → /epd/cortex - Rename store: swift-store.ts → cortex-store.ts Type Renames: - SwiftIntent → CortexIntent - SwiftStore → CortexStore - useSwiftStore → useCortexStore - SwiftContext → CortexContext - useSwiftVoice → useCortexVoice Documentation Updates (docs/intent/): - Safety Net → Nudge (Layer 3 rename) - SafetySuggestion → NudgeSuggestion - evaluateSafetyNet → evaluateNudge - SWIFT_* feature flags → CORTEX_* - All path references updated to match new structure Files affected: 47 files, ~700 lines changed 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
87 lines
2.2 KiB
TypeScript
87 lines
2.2 KiB
TypeScript
import { NextRequest, NextResponse } from 'next/server';
|
|
import { createClient } from '@/lib/auth/server';
|
|
import { getEncounters } from '@/app/epd/agenda/actions';
|
|
import { z } from 'zod';
|
|
|
|
/**
|
|
* Swift Agenda Query API
|
|
*
|
|
* GET /api/swift/agenda?start=2024-12-27&end=2024-12-27
|
|
*
|
|
* Returns appointments for the specified date range.
|
|
* Automatically filters by current user (practitioner_id).
|
|
*/
|
|
|
|
// Query parameter schema
|
|
const QuerySchema = z.object({
|
|
start: z.string().refine((val) => !isNaN(Date.parse(val)), {
|
|
message: 'start moet een geldige datum zijn',
|
|
}),
|
|
end: z.string().refine((val) => !isNaN(Date.parse(val)), {
|
|
message: 'end moet een geldige datum zijn',
|
|
}),
|
|
});
|
|
|
|
export async function GET(request: NextRequest) {
|
|
try {
|
|
// Auth check
|
|
const supabase = await createClient();
|
|
const {
|
|
data: { user },
|
|
error: authError,
|
|
} = await supabase.auth.getUser();
|
|
|
|
if (authError || !user) {
|
|
return NextResponse.json(
|
|
{ error: 'Niet geautoriseerd. Log opnieuw in.' },
|
|
{ status: 401 }
|
|
);
|
|
}
|
|
|
|
// Parse and validate query parameters
|
|
const searchParams = request.nextUrl.searchParams;
|
|
const start = searchParams.get('start');
|
|
const end = searchParams.get('end');
|
|
|
|
if (!start || !end) {
|
|
return NextResponse.json(
|
|
{ error: 'start en end parameters zijn verplicht' },
|
|
{ status: 400 }
|
|
);
|
|
}
|
|
|
|
const validation = QuerySchema.safeParse({ start, end });
|
|
if (!validation.success) {
|
|
const errorMessage = validation.error.issues
|
|
.map((e) => e.message)
|
|
.join(', ');
|
|
return NextResponse.json({ error: errorMessage }, { status: 400 });
|
|
}
|
|
|
|
// Fetch appointments
|
|
const appointments = await getEncounters({
|
|
startDate: start,
|
|
endDate: end,
|
|
practitionerId: user.id,
|
|
});
|
|
|
|
return NextResponse.json(
|
|
{
|
|
appointments,
|
|
count: appointments.length,
|
|
dateRange: { start, end },
|
|
},
|
|
{ status: 200 }
|
|
);
|
|
} catch (error) {
|
|
console.error('Error in agenda query API:', error);
|
|
return NextResponse.json(
|
|
{
|
|
error:
|
|
'Er ging iets mis bij het ophalen van afspraken. Probeer het opnieuw.',
|
|
},
|
|
{ status: 500 }
|
|
);
|
|
}
|
|
}
|