-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #84 from admisio/xlsx_export
(backend) (frontend) XLSX export
- Loading branch information
Showing
7 changed files
with
335 additions
and
14 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
apps/web/src/routes/admin/(authenticated)/export/csv/+server.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }); | ||
} | ||
}; |
24 changes: 24 additions & 0 deletions
24
apps/web/src/routes/admin/(authenticated)/export/xlsx/+server.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.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 }); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.