import { z } from 'zod' import { markRead } from '~/data/repositories/reads' import { resolveClient } from '~/lib/api-auth' import { problem } from '~/lib/problem' const bodySchema = z.object({ external_user_id: z.string().min(1), post_ids: z.array(z.uuid()).min(1).max(200), }) export async function POST(request: Request) { const client = await resolveClient(request) if (!client) { return problem(401, 'unauthorized') } if (!client.projectId) { return problem(422, 'client_without_project') } const parsed = bodySchema.safeParse(await request.json().catch(() => null)) if (!parsed.success) { return problem(400, 'invalid_body', parsed.error.issues.map(issue => issue.path.join('.')).join(', ')) } const marked = await markRead({ projectId: client.projectId, externalUserId: parsed.data.external_user_id, scope: client.scope, postIds: parsed.data.post_ids, }) return Response.json({ marked }) }