Skip to content

Commit 0c4e943

Browse files
Bugfixes to avoid server errors (#329)
This avoids server errors if the user didn't select a pharmacy in the first step.
1 parent 5140048 commit 0c4e943

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

app/routes/apply.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ module.exports = router => {
66
const data = req.session.data
77
const organisationCode = data.organisationCode
88
const organisation = data.organisations.find((organisation) => organisation.id === organisationCode)
9+
if (!organisation) { res.redirect('/apply/start'); return }
910

1011
res.render('apply/check-pharmacy', {
1112
organisation
@@ -17,19 +18,34 @@ module.exports = router => {
1718
const data = req.session.data
1819
const organisationCode = data.organisationCode
1920
const organisation = data.organisations.find((organisation) => organisation.id === organisationCode)
21+
if (!organisation) { res.redirect('/apply/start'); return }
2022

2123
res.render('apply/check', {
2224
organisation
2325
})
2426
})
2527

28+
// Check your email page
29+
router.get('/apply/check-your-email', (req, res) => {
30+
const data = req.session.data
31+
const organisationCode = data.organisationCode
32+
const organisation = data.organisations.find((organisation) => organisation.id === organisationCode)
33+
34+
if (!organisation) { res.redirect('/apply/start'); return }
35+
36+
res.render('apply/check-your-email', {
37+
organisation
38+
})
39+
})
40+
2641

2742
// Routing after the final check answers page
2843
router.post('/apply/answer-check', (req, res) => {
2944
const data = req.session.data
45+
const vaccineTypes = (data.vaccineTypes || [])
3046
let nextPage
3147

32-
if (data.vaccineTypes.includes('COVID-19') && data.organisationCode === 'FA02S') {
48+
if (vaccineTypes.includes('COVID-19') && data.organisationCode === 'FA02S') {
3349
nextPage = '/apply/no-contract'
3450
} else {
3551
nextPage = '/apply/check-your-email'
@@ -43,6 +59,7 @@ module.exports = router => {
4359
const data = req.session.data
4460
const organisationCode = data.organisationCode
4561
const organisation = data.organisations.find((organisation) => organisation.id === organisationCode)
62+
if (!organisation) { res.redirect('/apply/start'); return }
4663

4764
res.render('apply/welcome-email', {
4865
organisation

app/views/apply/check-pharmacy.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ <h1 class="nhsuk-heading-l">{{ pageName }}</h1>
3434
text: "Type"
3535
},
3636
value: {
37-
html: organisation.type
37+
text: organisation.type
3838
}
3939
},
4040
{
@@ -50,7 +50,7 @@ <h1 class="nhsuk-heading-l">{{ pageName }}</h1>
5050
text: "Address"
5151
},
5252
value: {
53-
html: organisation.address.line1 + "<br>" + organisation.address.town + "<br>" + organisation.address.postcode
53+
html: (organisation.address.line1 + "<br>" + organisation.address.town + "<br>" + organisation.address.postcode) if organisation.address else ""
5454
}
5555
}
5656
]

app/views/apply/check-your-email.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
<h2 class="nhsuk-heading-l">{{ pageName }}</h2>
1414

15-
<p>We've set up an account for you as a lead administrator for Addlestone Pharmacy.</p>
15+
<p>We've set up an account for you as a lead administrator for {{ organisation.name }}.</p>
1616

1717
<p>You will now get a welcome email which includes:</p>
1818
<ul>

0 commit comments

Comments
 (0)