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 }); + } +}; diff --git a/apps/web/src/routes/admin/(authenticated)/export/xlsx/+server.ts b/apps/web/src/routes/admin/(authenticated)/export/xlsx/+server.ts new file mode 100644 index 0000000..86287dd --- /dev/null +++ b/apps/web/src/routes/admin/(authenticated)/export/xlsx/+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.xlsx(); + return new Response(xlsx, { + status: 200, + headers: { + 'Content-Type': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', + // TODO: Můžeme doplnit čas atd. + 'Content-Disposition': `attachment; filename="vysledky.xlsx"` + } + }); + } catch { + return new Response('Čus 👀', { status: 403 }); + } +}; diff --git a/apps/web/src/routes/admin/(authenticated)/users/+page.svelte b/apps/web/src/routes/admin/(authenticated)/users/+page.svelte index 457dafb..8ad8d24 100644 --- a/apps/web/src/routes/admin/(authenticated)/users/+page.svelte +++ b/apps/web/src/routes/admin/(authenticated)/users/+page.svelte @@ -1,38 +1,17 @@