Skip to content

Commit 1218248

Browse files
committed
Remove /first-page endpoint since ettersending could not use it
1 parent 2e2abbb commit 1218248

File tree

7 files changed

+26
-61
lines changed

7 files changed

+26
-61
lines changed

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

-23
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,6 @@ import documentsService from '../../../services/documents/documentsService';
33
import { htmlResponseError } from '../../../utils/errorHandling';
44
import { logErrorWithStacktrace } from '../../../utils/errors';
55

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

5230
const documents = {
53-
frontPage,
5431
frontPageAndApplication,
5532
};
5633

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ import forstesideV2 from './forstesideV2';
1010
const { skjemabyggingProxyUrl } = config;
1111

1212
/*
13-
* TODO: This version of forsteside is deprecated. When all consumers have implemented version 2
14-
* we can remove the version parameter and make forstesideV2 (renamed) the running version
13+
* TODO: This version of forsteside is deprecated.
14+
* v2 is can be removed, but the default version is used by fyllut-ettersending
15+
* @deprecated
1516
**/
1617
const forsteside = {
1718
post: async (req: Request, res: Response, next: NextFunction) => {

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

+9-29
Original file line numberDiff line numberDiff line change
@@ -5,37 +5,14 @@ import applicationService from './applicationService';
55
import frontPageService from './frontPageService';
66
import { mergeFiles } from './gotenbergService';
77

8-
interface FrontPageProps {
8+
interface FrontPageAndApplicationProps {
99
accessToken: string;
1010
form: NavFormType;
11+
submissionMethod: string;
1112
submission: Submission;
1213
language: string;
13-
unitNumber: string;
14-
}
15-
16-
const frontPage = async (props: FrontPageProps) => {
17-
const { accessToken, form, submission, language, unitNumber } = props;
18-
19-
const frontPageResponse: any = frontPageService.createPdf({
20-
accessToken,
21-
form,
22-
submission,
23-
language,
24-
unitNumber,
25-
});
26-
27-
const frontPagePdf = base64Decode(frontPageResponse.foersteside);
28-
29-
if (frontPagePdf === undefined) {
30-
throw htmlResponseError('Generering av førstesideark feilet');
31-
}
32-
33-
return Buffer.from(new Uint8Array(frontPagePdf));
34-
};
35-
36-
interface FrontPageAndApplicationProps extends FrontPageProps {
3714
translations: I18nTranslationMap;
38-
submissionMethod: string;
15+
unitNumber: string;
3916
}
4017

4118
const frontPageAndApplication = async (props: FrontPageAndApplicationProps) => {
@@ -51,6 +28,10 @@ const frontPageAndApplication = async (props: FrontPageAndApplicationProps) => {
5128

5229
const frontPagePdf = base64Decode(frontPageResponse.foersteside);
5330

31+
if (frontPagePdf === undefined) {
32+
throw htmlResponseError('Generering av førstesideark PDF feilet');
33+
}
34+
5435
const applicationResponse: any = await applicationService.createPdf(
5536
accessToken,
5637
form,
@@ -62,8 +43,8 @@ const frontPageAndApplication = async (props: FrontPageAndApplicationProps) => {
6243

6344
const applicationPdf = base64Decode(applicationResponse.data);
6445

65-
if (applicationPdf === undefined || frontPagePdf === undefined) {
66-
throw htmlResponseError('Generering av førstesideark eller søknads PDF feilet');
46+
if (applicationPdf === undefined) {
47+
throw htmlResponseError('Generering av søknads PDF feilet');
6748
}
6849

6950
const documents = [frontPagePdf, applicationPdf];
@@ -80,7 +61,6 @@ const frontPageAndApplication = async (props: FrontPageAndApplicationProps) => {
8061
};
8162

8263
const documentsService = {
83-
frontPage,
8464
frontPageAndApplication,
8565
};
8666

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

+8-3
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,16 @@ const createPdf = async (props: CreatePdfProps) => {
2727

2828
const body = forstesideUtils.genererFoerstesideData(form, submission, language, recipients, unitNumber);
2929

30-
const response = await createRequest(accessToken, JSON.stringify(body));
30+
const response = await createPdfRequest(accessToken, JSON.stringify(body));
3131

3232
log(body, response);
3333

34-
return response;
34+
return {
35+
...(response as object),
36+
navSkjemaId: body.navSkjemaId,
37+
overskriftstittel: body.overskriftstittel,
38+
spraakkode: body.spraakkode,
39+
};
3540
};
3641

3742
const getRecipients = async (formProperties: FormPropertiesType): Promise<Recipient[] | undefined> => {
@@ -52,7 +57,7 @@ const getRecipients = async (formProperties: FormPropertiesType): Promise<Recipi
5257
}
5358
};
5459

55-
const createRequest = async (accessToken: string, body?: BodyInit) => {
60+
const createPdfRequest = async (accessToken: string, body?: BodyInit) => {
5661
const { skjemabyggingProxyUrl } = config;
5762

5863
const response = await fetch(`${skjemabyggingProxyUrl}/foersteside`, {

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ const formatPDFDate = (date: Date) => {
5050
};
5151

5252
// Generisk metode for kall til mot Gotenberg gitt rute og preparert FormData
53-
export const callGotenberg = async (language: string, route: string, formData: FormData): Promise<any> => {
53+
export const callGotenberg = async (language: string = 'no', route: string, formData: FormData): Promise<any> => {
5454
const url = language.toLowerCase().startsWith('en') ? gotenbergUrlEn : gotenbergUrl;
55-
console.log(`Calling Gotenberg with url = ${url}/${route}`);
55+
console.log(`Calling Gotenberg with url = ${url}${route}`);
5656

5757
try {
5858
// Send the request to Gotenberg

packages/shared-components/src/components/button/DownloadApplicationButton.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ const DownloadApplicationButton = ({
5656
enhetNummer,
5757
submissionMethod: submissionMethod ?? 'paper',
5858
}}
59-
actionUrl={`${fyllutBaseURL}/api/documents/front-page`}
59+
actionUrl={`${fyllutBaseURL}/api/documents/front-page-and-application`}
6060
isValid={isValid}
6161
onSuccess={onSuccess}
6262
onError={onError}

packages/shared-components/src/components/button/DownloadPdfButton.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@ const DownloadPdfButton = ({
3131
const response: Blob = await http.post(actionUrl, values, {
3232
Accept: http.MimeType.PDF,
3333
});
34-
3534
const url = window.URL.createObjectURL(response);
35+
if (!url) {
36+
throw new Error('Could not create PDF url');
37+
}
3638
const a = document.createElement('a');
3739
a.href = url;
3840
a.download = fileName;

0 commit comments

Comments
 (0)