Skip to content

Commit

Permalink
feat: expose csv export
Browse files Browse the repository at this point in the history
  • Loading branch information
EETagent committed Feb 24, 2024
1 parent e22510f commit 9e05acf
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions apps/web/src/routes/admin/(authenticated)/export/csv/+server.ts
Original file line number Diff line number Diff line change
@@ -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 });
}
};

0 comments on commit 9e05acf

Please sign in to comment.