diff --git a/apps/web/src/routes/admin/(authenticated)/export/csv/+server.ts b/apps/web/src/routes/admin/(authenticated)/export/csv/+server.ts new file mode 100644 index 0000000..59a2ac7 --- /dev/null +++ b/apps/web/src/routes/admin/(authenticated)/export/csv/+server.ts @@ -0,0 +1,24 @@ +import type { RequestHandler } from './$types'; + +import { router } from '@testy/trpc/server/router'; +import { createContext } from '@testy/trpc/server/createContext'; + +export const GET: RequestHandler = async (event) => { + try { + const trpc = router.createCaller(await createContext(event)); + + await trpc.auth.admin(); + + const xlsx = await trpc.users.csv(); + const date = new Date().toISOString().split('.')[0]; + return new Response(xlsx, { + status: 200, + headers: { + 'Content-Type': 'text/csv', + 'Content-Disposition': `attachment; filename="vysledky_${date}.csv"` + } + }); + } catch { + return new Response('Čus 👀', { status: 403 }); + } +};