Skip to content

Commit e13ddf6

Browse files
authored
Fix the editing of school sessions (#253)
Restrict iteration of vaccination periods to when we're editing clinic sessions, as the array of IDs was undefined rather than empty. But also, create an empty array in the Session ctor too, to guard against future issues. One final change was to prevent changing a school session to a clinic session. I've never known this to work, and it feels a highly unlikely thing to want to do, so let's not offer it. (To be fair, changing school kinda breaks stuff too (leaving children from one school in another school's session), but let's not go there. Hopefully no-one does that.)
1 parent 7d5e845 commit e13ddf6

3 files changed

Lines changed: 18 additions & 16 deletions

File tree

app/controllers/session.js

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -498,11 +498,13 @@ export const sessionController = {
498498
if (!session) {
499499
// NB: response.locals.session was set in read()
500500
session = Session.create(response.locals.session, data.wizard)
501-
response.locals.session.vaccinationPeriods.forEach(
502-
(vaccinationPeriod) => {
503-
ClinicVaccinationPeriod.create(vaccinationPeriod, data.wizard)
504-
}
505-
)
501+
if (session.type === SessionType.Clinic) {
502+
response.locals.session.vaccinationPeriods.forEach(
503+
(vaccinationPeriod) => {
504+
ClinicVaccinationPeriod.create(vaccinationPeriod, data.wizard)
505+
}
506+
)
507+
}
506508
}
507509

508510
// Set up the transaction metadata that controls how some clinic values are entered
@@ -526,15 +528,17 @@ export const sessionController = {
526528
}
527529
}
528530

531+
// Give access to the data needed for the summaryRows
529532
response.locals.session = new Session(session, data)
530533

531-
// Generate summary info for the edit page
532-
response.locals.vaccinationPeriodsSummary = getVaccinationPeriodsSummary(
533-
session.vaccination_period_ids.map((period_id) =>
534-
ClinicVaccinationPeriod.findOne(period_id, data.wizard)
535-
),
536-
session.appointmentLength
537-
)
534+
if (session.type === SessionType.Clinic) {
535+
response.locals.vaccinationPeriodsSummary = getVaccinationPeriodsSummary(
536+
session.vaccination_period_ids.map((period_id) =>
537+
ClinicVaccinationPeriod.findOne(period_id, data.wizard)
538+
),
539+
session.appointmentLength
540+
)
541+
}
538542

539543
// Show back link to session page
540544
response.locals.back = session.uri

app/models/session.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ export class Session {
9494
if (this.type === SessionType.Clinic) {
9595
this.clinic_id = options?.clinic_id
9696
this.registration = false
97-
this.vaccination_period_ids = options?.vaccination_period_ids
97+
this.vaccination_period_ids = options?.vaccination_period_ids || []
9898
this.appointmentLength = options?.appointmentLength
9999
}
100100

app/views/session/edit.njk

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@
1919
headingSize: "m"
2020
},
2121
rows: summaryRows(session, {
22-
type: {
23-
href: session.uri + "/edit/type" if session.consentWindow == ConsentWindow.Opening
24-
},
22+
type: {},
2523
clinic: {
2624
href: session.uri + "/edit/clinic"
2725
},

0 commit comments

Comments
 (0)