File tree Expand file tree Collapse file tree 2 files changed +21
-7
lines changed
Expand file tree Collapse file tree 2 files changed +21
-7
lines changed Original file line number Diff line number Diff line change @@ -273,8 +273,12 @@ module.exports = router => {
273273 const organisation = data . organisations . find ( ( org ) => org . id === id )
274274 if ( ! organisation ) { res . redirect ( '/regions/' ) ; return }
275275
276- const vaccines = organisation . vaccines || [ ]
277- const vaccinesNotYetAdded = vaccines . filter ( ( vaccine ) => vaccine . status !== "enabled" )
276+ const organisationVaccines = organisation . vaccines || [ ]
277+ const vaccineEnabledNames = organisationVaccines . filter ( ( vaccine ) => vaccine . status === "enabled" ) . map ( ( vaccine ) => vaccine . name )
278+
279+ const allVaccines = data . vaccines
280+
281+ const vaccinesNotYetAdded = allVaccines . filter ( ( vaccine ) => ! vaccineEnabledNames . includes ( vaccine . name ) )
278282
279283 res . render ( 'regions/add-vaccines' , {
280284 organisation,
@@ -293,10 +297,20 @@ module.exports = router => {
293297
294298 const vaccines = organisation . vaccines || [ ]
295299
296- for ( vaccine of vaccines ) {
297- if ( vaccinesToAdd . includes ( vaccine . name ) ) {
298- vaccine . status = "enabled"
300+ for ( vaccineToAdd of vaccinesToAdd ) {
301+
302+ const existingVaccine = vaccines . find ( ( vaccine ) => vaccine . name === vaccineToAdd )
303+
304+ if ( existingVaccine ) {
305+ existingVaccine . status = "enabled"
306+ } else {
307+
308+ vaccines . push ( {
309+ name : vaccineToAdd ,
310+ status : "enabled"
311+ } )
299312 }
313+
300314 }
301315
302316 res . redirect ( `/regions/organisations/${ id } ` )
Original file line number Diff line number Diff line change @@ -31,14 +31,14 @@ <h1 class="nhsuk-heading-l">{{ organisation.name }}</h1>
3131 {% else %}
3232
3333 < p > They can record
34- {% if (vaccinesEnabled | length) == 4 %}
34+ {% if (vaccinesEnabled | length) == (data.vaccines | length) %}
3535 all
3636 {% else %}
3737 {{ vaccinesEnabled | sort(false, false, "name") | pluck("name") | formatList }}
3838 {% endif %}
3939 vaccinations.
4040
41- {% if (vaccinesEnabled | length) < 4 %}
41+ {% if (vaccinesEnabled | length) < (data.vaccines | length) %}
4242 < a href ="/regions/organisations/{{organisation.id}}/add-vaccines "> Add vaccines< span class ="nhsuk-u-visually-hidden "> </ span > </ a >
4343 {% endif %}
4444 </ p >
You can’t perform that action at this time.
0 commit comments