Skip to content

Commit 975da82

Browse files
Add previous vaccination exports to exports list
1 parent 95862eb commit 975da82

5 files changed

Lines changed: 57 additions & 24 deletions

File tree

app/controllers/download.js

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@ import { getDateValueDifference } from '../utils/date.js'
55
import { getResults, getPagination } from '../utils/pagination.js'
66

77
export const downloadController = {
8+
read(request, response, next, download_id) {
9+
response.locals.download = Download.findOne(
10+
download_id,
11+
request.session.data
12+
)
13+
14+
next()
15+
},
16+
817
readAll(request, response, next) {
918
response.locals.downloads = Download.findAll(request.session.data)
1019

@@ -95,8 +104,8 @@ export const downloadController = {
95104
const { account } = request.app.locals
96105
const { data } = request.session
97106

98-
const { type } = request.body.download
99-
const programme_id = programmesData[type].id
107+
const { programmeType } = request.body.download
108+
const programme_id = programmesData[programmeType].id
100109
const programme = Programme.findOne(programme_id, data)
101110

102111
const createdDownload = Download.create(
@@ -117,6 +126,19 @@ export const downloadController = {
117126
response.header('Content-Type', mimetype)
118127
response.header('Content-disposition', `attachment; filename=${fileName}`)
119128

129+
response.end(buffer)
130+
},
131+
132+
download(request, response) {
133+
const { data } = request.session
134+
const { download } = response.locals
135+
136+
// Generate and return file
137+
const { buffer, fileName, mimetype } = download.createFile(data)
138+
139+
response.header('Content-Type', mimetype)
140+
response.header('Content-disposition', `attachment; filename=${fileName}`)
141+
120142
response.end(buffer)
121143
}
122144
}

app/models/download.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,12 @@ export class Download {
109109
* @returns {string} Name
110110
*/
111111
get name() {
112-
if (this.programme) {
113-
return this.programme.name
112+
switch (true) {
113+
case this.type === DownloadType.Report:
114+
return `${this.programme.name} vaccination records`
115+
default:
116+
return 'Download'
114117
}
115-
116-
return 'Download'
117118
}
118119

119120
/**
@@ -346,7 +347,7 @@ export class Download {
346347
* @returns {string} URI
347348
*/
348349
get uri() {
349-
return `/reports/${this.programme_id}/download/${this.id}`
350+
return `/downloads/${this.id}`
350351
}
351352

352353
/**

app/routes/download.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,8 @@ router.post('/', download.filterList)
1010
router.get('/new', download.form)
1111
router.post('/new', download.create)
1212

13+
router.param('download_id', download.read)
14+
15+
router.get('/:download_id/download', download.download)
16+
1317
export const downloadRoutes = router

app/views/download/form.njk

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
{% extends "_layouts/form.njk" %}
2+
23
{% set confirmButtonText = __("download.new.confirm") %}
34
{% set title = __("download.new.label") %}
5+
46
{% block form %}
57
{{ appHeading({
68
title: title
79
}) }}
10+
811
{{ radios({
912
formGroup: {
1013
classes: "nhsuk-u-margin-bottom-8"
@@ -18,6 +21,7 @@
1821
items: academicYearItems,
1922
decorate: "download.year"
2023
}) }}
24+
2125
{{ radios({
2226
formGroup: {
2327
classes: "nhsuk-u-margin-bottom-8"
@@ -29,8 +33,9 @@
2933
}
3034
},
3135
items: programmeTypeItems,
32-
decorate: "download.type"
36+
decorate: "download.programmeType"
3337
}) }}
38+
3439
{{ dateInput({
3540
formGroup: {
3641
classes: "nhsuk-u-margin-bottom-8"
@@ -43,6 +48,7 @@
4348
},
4449
decorate: "download.startAt_"
4550
}) }}
51+
4652
{{ dateInput({
4753
formGroup: {
4854
classes: "nhsuk-u-margin-bottom-8"
@@ -55,21 +61,21 @@
5561
},
5662
decorate: "download.endAt_"
5763
}) }}
58-
{% if account.role == UserRole.DataConsumer %}
59-
{{ checkboxes({
60-
formGroup: {
61-
classes: "nhsuk-u-margin-bottom-8"
62-
},
63-
fieldset: {
64-
legend: {
65-
classes: "nhsuk-fieldset__legend--m",
66-
text: __("download.teams.title")
67-
}
68-
},
69-
items: teamItems,
70-
decorate: "download.team_ids"
71-
}) }}
72-
{% endif %}
64+
65+
{{ checkboxes({
66+
formGroup: {
67+
classes: "nhsuk-u-margin-bottom-8"
68+
},
69+
fieldset: {
70+
legend: {
71+
classes: "nhsuk-fieldset__legend--m",
72+
text: __("download.teams.title")
73+
}
74+
},
75+
items: teamItems,
76+
decorate: "download.team_ids"
77+
}) if account.role == UserRole.DataConsumer }}
78+
7379
{{ radios({
7480
formGroup: {
7581
classes: "nhsuk-u-margin-bottom-8"

app/views/download/list.njk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
heading: download.name,
7777
headingSize: "s",
7878
headingLevel: 4,
79-
href: download.uri,
79+
href: download.uri + "/download",
8080
clickable: true
8181
},
8282
rows: summaryRows(download, {

0 commit comments

Comments
 (0)