-
Notifications
You must be signed in to change notification settings - Fork 179
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
Showing
1 changed file
with
13 additions
and
14 deletions.
There are no files selected for viewing
27 changes: 13 additions & 14 deletions
27
frontend/src/routes/(app)/(internal)/compliance-assessments/[id=uuid]/export/word/+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 |
---|---|---|
@@ -1,23 +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}/word_report/`; | ||
const URLModel = 'compliance-assessments'; | ||
const endpoint = `${BASE_API_URL}/${URLModel}/${params.id}/word_report/`; | ||
|
||
const res = await fetch(endpoint); | ||
if (!res.ok) { | ||
error(400, 'Error fetching the Word file'); | ||
} | ||
const res = await fetch(endpoint); | ||
if (!res.ok) { | ||
error(400, 'Error fetching the Word file'); | ||
} | ||
|
||
const fileName = `audit-report-${new Date().toISOString()}.docx`; | ||
const fileName = `audit-report-${new Date().toISOString()}.docx`; | ||
|
||
return new Response(await res.blob(), { | ||
headers: { | ||
'Content-Type': 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', | ||
'Content-Disposition': `attachment; filename="${fileName}"` | ||
} | ||
}); | ||
return new Response(await res.blob(), { | ||
headers: { | ||
'Content-Type': 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', | ||
'Content-Disposition': `attachment; filename="${fileName}"` | ||
} | ||
}); | ||
}; |