-
Notifications
You must be signed in to change notification settings - Fork 181
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d0346a3
commit 775802e
Showing
5 changed files
with
60 additions
and
4 deletions.
There are no files selected for viewing
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
22 changes: 22 additions & 0 deletions
22
frontend/src/routes/(app)/compliance-assessments/[id=uuid]/action-plan/export/pdf/+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,22 @@ | ||
import { BASE_API_URL } from '$lib/utils/constants'; | ||
|
||
import { error } from '@sveltejs/kit'; | ||
import type { RequestHandler } from './$types'; | ||
export const GET: RequestHandler = async ({ fetch, params }) => { | ||
const URLModel = 'compliance-assessments'; | ||
const endpoint = `${BASE_API_URL}/${URLModel}/${params.id}/action_plan_pdf/`; | ||
|
||
const res = await fetch(endpoint); | ||
if (!res.ok) { | ||
error(400, 'Error fetching the PDF file'); | ||
} | ||
|
||
const fileName = `AP-${params.id}-${new Date().toISOString()}.pdf`; | ||
|
||
return new Response(await res.blob(), { | ||
headers: { | ||
'Content-Type': 'text/pdf', | ||
'Content-Disposition': `attachment; filename="${fileName}"` | ||
} | ||
}); | ||
}; |