Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { ComponentType, type PageFileUpload } from '@defra/forms-model'
import {
ComponentType,
type FormMetadata,
type PageFileUpload
} from '@defra/forms-model'
import Boom from '@hapi/boom'
import { wait } from '@hapi/hoek'
import { type ValidationErrorItem } from 'joi'
Expand Down Expand Up @@ -423,6 +427,7 @@ export class FileUploadPageController extends QuestionPageController {
) {
const { fileUpload, href, path } = this
const { options, schema } = fileUpload
const params = request.params

const files = this.getFilesFromState(state)

Expand All @@ -436,7 +441,19 @@ export class FileUploadPageController extends QuestionPageController {
const outputEmail =
this.model.def.outputEmail ?? 'defraforms@defra.gov.uk'

const newUpload = await initiateUpload(href, outputEmail, options.accept)
const { formsService } = this.model.services
const { getFormMetadata } = formsService
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
const metadata = params?.slug
? await getFormMetadata(params.slug)
: ({} as FormMetadata)
const newUpload = await initiateUpload(
href,
outputEmail,
metadata,
this.href,
options.accept
)

if (newUpload === undefined) {
throw Boom.badRequest('Unexpected empty response from initiateUpload')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@
// Submit data
request.logger.info(logTags, 'Submitting data')
const submitResponse = await submitData(
formMetadata,
model,
items,
emailAddress,
Expand Down Expand Up @@ -246,6 +247,7 @@
}

function submitData(
form: FormMetadata,
model: FormModel,
items: DetailItem[],
retrievalKey: string,
Expand Down Expand Up @@ -282,7 +284,12 @@
value: getAnswer(subItem.field, subItem.state, { format: 'data' })
}))
)
}))
})),
form: {

Check failure on line 288 in src/server/plugins/engine/pageControllers/SummaryPageController.ts

View workflow job for this annotation

GitHub Actions / Build

Object literal may only specify known properties, and 'form' does not exist in type 'SubmitPayload'.
id: form.id,
name: form.title,
slug: form.slug
}
}

return submit(payload)
Expand Down
17 changes: 15 additions & 2 deletions src/server/plugins/engine/services/uploadService.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,17 @@ const stagingPrefix = config.get('stagingPrefix')
* Initiates a CDP file upload
* @param {string} path - the path of the page in the form
* @param {string} retrievalKey - the retrieval key for the files
* @param {FormMetadata} formMetadata
* @param {string} pagePath - the path to the page
* @param {string} [mimeTypesCsv] - the csv string of accepted mimeTypes
*/
export async function initiateUpload(path, retrievalKey, mimeTypesCsv) {
export async function initiateUpload(
path,
retrievalKey,
formMetadata,
pagePath,
mimeTypesCsv
) {
const postJsonByType =
/** @type {typeof postJson<UploadInitiateResponse>} */ (postJson)

Expand All @@ -29,7 +37,11 @@ export async function initiateUpload(path, retrievalKey, mimeTypesCsv) {
s3Bucket: uploaderBucketName,
s3Path: stagingPrefix,
metadata: {
retrievalKey
retrievalKey,
formId: formMetadata.id,
formSlug: formMetadata.slug,
formName: formMetadata.title,
pagePath
},
mimeTypes
// maxFileSize: 25 * 1000 * 1000
Expand Down Expand Up @@ -60,5 +72,6 @@ export async function getUploadStatus(uploadId) {
}

/**
* @import { FormMetadata } from '@defra/forms-model'
* @import { UploadInitiateResponse, UploadStatusResponse } from '~/src/server/plugins/engine/types.js'
*/
7 changes: 6 additions & 1 deletion test/form/govuk-notify.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,12 @@ describe('Submission journey test', () => {
],
repeaters: [],
retrievalKey: 'enrique.chase@defra.gov.uk',
sessionId: expect.any(String)
sessionId: expect.any(String),
form: {
id: '661e4ca5039739ef2902b214',
name: 'Test form',
slug: 'test-form'
}
})

// Status page
Expand Down
7 changes: 6 additions & 1 deletion test/form/journey-basic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,12 @@ describe('Form journey', () => {
],
repeaters: [],
retrievalKey: 'enrique.chase@defra.gov.uk',
sessionId: expect.any(String)
sessionId: expect.any(String),
form: {
id: '661e4ca5039739ef2902b214',
name: 'Test form',
slug: 'test-form'
}
})

expect(response.statusCode).toBe(StatusCodes.SEE_OTHER)
Expand Down
7 changes: 6 additions & 1 deletion test/form/persist-files.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,12 @@ describe('Submission journey test', () => {
],
repeaters: [],
retrievalKey: 'enrique.chase@defra.gov.uk',
sessionId: expect.any(String)
sessionId: expect.any(String),
form: {
id: '661e4ca5039739ef2902b214',
name: 'Test form',
slug: 'test-form'
}
})

expect(submitRes.statusCode).toBe(StatusCodes.SEE_OTHER)
Expand Down
7 changes: 6 additions & 1 deletion test/form/repeat.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,12 @@ describe('Repeat POST tests', () => {
}
],
retrievalKey: 'enrique.chase@defra.gov.uk',
sessionId: expect.any(String)
sessionId: expect.any(String),
form: {
id: '661e4ca5039739ef2902b214',
name: 'Test form',
slug: 'test-form'
}
})
})

Expand Down
Loading