Skip to content

Commit 5f5c00f

Browse files
Add previous vaccination exports to exports list
1 parent 95862eb commit 5f5c00f

5 files changed

Lines changed: 36 additions & 9 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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
}
3030
},
3131
items: programmeTypeItems,
32-
decorate: "download.type"
32+
decorate: "download.programmeType"
3333
}) }}
3434
{{ dateInput({
3535
formGroup: {

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)