- User.min_quota_pct Int @default(20) + ClaudeWorker.last_quota_pct/last_quota_check_at - Migratie add_worker_quota_gate - lib/schemas/user.ts: minQuotaPctSchema (int, 1-100) - actions/settings.ts: updateMinQuotaPctAction met auth/demo/zod-guard - MinQuotaEditor component met numeric input en DemoTooltip - Settings-pagina: Worker-instellingen sectie Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
29 lines
959 B
TypeScript
29 lines
959 B
TypeScript
'use server'
|
|
|
|
import { revalidatePath } from 'next/cache'
|
|
import { cookies } from 'next/headers'
|
|
import { getIronSession } from 'iron-session'
|
|
import { prisma } from '@/lib/prisma'
|
|
import { SessionData, sessionOptions } from '@/lib/session'
|
|
import { minQuotaPctSchema } from '@/lib/schemas/user'
|
|
|
|
async function getSession() {
|
|
return getIronSession<SessionData>(await cookies(), sessionOptions)
|
|
}
|
|
|
|
export async function updateMinQuotaPctAction(value: number) {
|
|
const session = await getSession()
|
|
if (!session.userId) return { error: 'Niet ingelogd' }
|
|
if (session.isDemo) return { error: 'Niet beschikbaar in demo-modus', status: 403 }
|
|
|
|
const parsed = minQuotaPctSchema.safeParse(value)
|
|
if (!parsed.success) return { error: 'Waarde moet tussen 1 en 100 liggen', status: 422 }
|
|
|
|
await prisma.user.update({
|
|
where: { id: session.userId },
|
|
data: { min_quota_pct: parsed.data },
|
|
})
|
|
|
|
revalidatePath('/settings')
|
|
return { success: true }
|
|
}
|