Skip to content

Commit 6fe54fa

Browse files
committed
Support only download application
1 parent d1d8385 commit 6fe54fa

File tree

4 files changed

+59
-8
lines changed

4 files changed

+59
-8
lines changed

packages/fyllut-backend/src/routers/api/documents/documents.ts

+26-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,31 @@
11
import { RequestHandler } from 'express';
22
import documentsService from '../../../services/documents/documentsService';
3-
import { htmlResponseError } from '../../../utils/errorHandling';
43
import { logErrorWithStacktrace } from '../../../utils/errors';
54

5+
const application: RequestHandler = async (req, res, next) => {
6+
try {
7+
const { form, submission, language, enhetNummer, submissionMethod, translations } = req.body;
8+
const formParsed = JSON.parse(form);
9+
const submissionParsed = JSON.parse(submission);
10+
11+
const fileBuffer = await documentsService.application({
12+
form: formParsed,
13+
submission: submissionParsed,
14+
language,
15+
unitNumber: enhetNummer,
16+
accessToken: req.headers.AzureAccessToken as string,
17+
submissionMethod,
18+
translations,
19+
});
20+
res.contentType('application/pdf');
21+
res.setHeader('Content-Disposition', `inline; filename=${encodeURIComponent(`${formParsed.path}.pdf`)}`);
22+
res.send(fileBuffer);
23+
} catch (e) {
24+
logErrorWithStacktrace(e as Error);
25+
next(e);
26+
}
27+
};
28+
629
const coverPageAndApplication: RequestHandler = async (req, res, next) => {
730
try {
831
const { form, submission, language, enhetNummer, submissionMethod, translations } = req.body;
@@ -23,11 +46,12 @@ const coverPageAndApplication: RequestHandler = async (req, res, next) => {
2346
res.send(fileBuffer);
2447
} catch (e) {
2548
logErrorWithStacktrace(e as Error);
26-
next(htmlResponseError('Generering av førstesideark eller soknads PDF feilet'));
49+
next(e);
2750
}
2851
};
2952

3053
const documents = {
54+
application,
3155
coverPageAndApplication,
3256
};
3357

packages/fyllut-backend/src/routers/api/documents/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import documents from './documents';
55
const documentsRouter = express.Router();
66
const { azureSkjemabyggingProxy } = initApiConfig();
77

8+
documentsRouter.post('/application', azureSkjemabyggingProxy, documents.application);
89
documentsRouter.post('/front-page-and-application', azureSkjemabyggingProxy, documents.coverPageAndApplication);
910

1011
export default documentsRouter;

packages/fyllut-backend/src/services/documents/documentsService.ts

+26-1
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,37 @@ import applicationService from './applicationService';
55
import coverPageService from './coverPageService';
66
import { mergeFiles } from './gotenbergService';
77

8-
interface CoverPageAndApplicationProps {
8+
interface ApplicationProps {
99
accessToken: string;
1010
form: NavFormType;
1111
submissionMethod: string;
1212
submission: Submission;
1313
language: string;
1414
translations: I18nTranslationMap;
15+
}
16+
17+
const application = async (props: CoverPageAndApplicationProps) => {
18+
const { accessToken, form, submission, language, translations, submissionMethod } = props;
19+
20+
const applicationResponse: any = await applicationService.createPdf(
21+
accessToken,
22+
form,
23+
submission,
24+
submissionMethod,
25+
translations,
26+
language,
27+
);
28+
29+
const applicationPdf = base64Decode(applicationResponse.data);
30+
31+
if (applicationPdf === undefined) {
32+
throw htmlResponseError('Generering av søknads PDF feilet');
33+
}
34+
35+
return Buffer.from(applicationPdf);
36+
};
37+
38+
interface CoverPageAndApplicationProps extends ApplicationProps {
1539
unitNumber: string;
1640
}
1741

@@ -61,6 +85,7 @@ const coverPageAndApplication = async (props: CoverPageAndApplicationProps) => {
6185
};
6286

6387
const documentsService = {
88+
application,
6489
coverPageAndApplication,
6590
};
6691

packages/shared-components/src/pages/prepare-innsending/PrepareIngenInnsendingPage.tsx

+6-5
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,13 @@ export function PrepareIngenInnsendingPage({ form, submission, translations, for
3131
<div className={styles.content}>
3232
<section id="maincontent" className="fyllut-layout" tabIndex={-1}>
3333
<section className="main-col" aria-label={translate(form.properties.innsendingOverskrift)}>
34-
<div className="wizard-page">
35-
<Heading level="3" size="medium" spacing>
36-
{translate(form.properties.innsendingOverskrift)}
37-
</Heading>
38-
<BodyShort className="mb">{translate(form.properties.innsendingForklaring)}</BodyShort>
34+
<Heading level="3" size="medium" spacing>
35+
{translate(form.properties.innsendingOverskrift)}
36+
</Heading>
37+
<BodyShort className="mb">{translate(form.properties.innsendingForklaring)}</BodyShort>
38+
<div className="mb-4">
3939
<DownloadCoverPageAndApplicationButton
40+
type="application"
4041
form={form}
4142
submission={submission}
4243
translations={translations}

0 commit comments

Comments
 (0)