generated from ministryofjustice/hmpps-template-typescript
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Populate calendar with visit sessions
- Loading branch information
Showing
6 changed files
with
192 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 17 additions & 85 deletions
102
server/routes/bookingJourney/selectVisitDateTimeController.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,108 +1,40 @@ | ||
import type { RequestHandler } from 'express' | ||
import { VisitSessionsService } from '../../services' | ||
|
||
type CalendarData = { | ||
selectedDate: string | ||
months: Record< | ||
string, | ||
{ | ||
startDayColumn: number | ||
dates: Record<string, { reference: string; time: string; duration: string }[]> | ||
} | ||
> | ||
} | ||
|
||
const calendarData: CalendarData = { | ||
selectedDate: '2024-02-24', | ||
months: { | ||
'February 2024': { | ||
startDayColumn: 4, // 1 = first date is a Monday | ||
dates: { | ||
'2024-02-22': [], | ||
'2024-02-23': [], | ||
'2024-02-24': [ | ||
{ reference: 'a', time: '10am to 11:30am', duration: '1 hour and 30 minutes' }, | ||
{ reference: 'b', time: '4:30pm to 6:30am', duration: '2 hours' }, | ||
], | ||
'2024-02-25': [], | ||
'2024-02-26': [{ reference: 'c', time: '11am to 12:30am', duration: '1 hour and 30 minutes' }], | ||
'2024-02-27': [ | ||
{ reference: 'd', time: '9:30am to 10:30am', duration: '1 hour' }, | ||
{ reference: 'e', time: '1pm to 3pm', duration: '2 hours' }, | ||
], | ||
'2024-02-28': [], | ||
'2024-02-29': [ | ||
{ reference: 'f', time: '10am to 11:30am', duration: '1 hour and 30 minutes' }, | ||
{ reference: 'g', time: '4:30pm to 6:30am', duration: '2 hours' }, | ||
], | ||
}, | ||
}, | ||
|
||
'March 2024': { | ||
startDayColumn: 5, | ||
dates: { | ||
'2024-03-01': [], | ||
'2024-03-02': [{ reference: 'h', time: '11am to 12:30am', duration: '1 hour and 30 minutes' }], | ||
'2024-03-03': [ | ||
{ reference: 'i', time: '9:30am to 10:30am', duration: '1 hour' }, | ||
{ reference: 'j', time: '1pm to 3pm', duration: '2 hours' }, | ||
], | ||
'2024-03-04': [], | ||
'2024-03-05': [], | ||
'2024-03-06': [ | ||
{ reference: 'k', time: '10am to 11:30am', duration: '1 hour and 30 minutes' }, | ||
{ reference: 'l', time: '4:30pm to 6:30am', duration: '2 hours' }, | ||
], | ||
'2024-03-07': [], | ||
'2024-03-08': [], | ||
'2024-03-09': [{ reference: 'm', time: '11am to 12:30am', duration: '1 hour and 30 minutes' }], | ||
'2024-03-10': [ | ||
{ reference: 'n', time: '9:30am to 10:30am', duration: '1 hour' }, | ||
{ reference: 'o', time: '1pm to 3pm', duration: '2 hours' }, | ||
], | ||
'2024-03-11': [], | ||
'2024-03-12': [], | ||
'2024-03-13': [ | ||
{ reference: 'p', time: '10am to 11:30am', duration: '1 hour and 30 minutes' }, | ||
{ reference: 'q', time: '4:30pm to 6:30am', duration: '2 hours' }, | ||
], | ||
'2024-03-14': [{ reference: 'r', time: '11am to 12:30am', duration: '1 hour and 30 minutes' }], | ||
'2024-03-15': [], | ||
'2024-03-16': [ | ||
{ reference: 'd', time: '9:30am to 10:30am', duration: '1 hour' }, | ||
{ reference: 't', time: '1pm to 3pm', duration: '2 hours' }, | ||
], | ||
'2024-03-17': [ | ||
{ reference: 'u', time: '10am to 11:30am', duration: '1 hour and 30 minutes' }, | ||
{ reference: 'v', time: '4:30pm to 6:30am', duration: '2 hours' }, | ||
], | ||
'2024-03-18': [{ reference: 'w', time: '11am to 12:30am', duration: '1 hour and 30 minutes' }], | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
export default class SelectVisitDateTimeController { | ||
public constructor(private readonly visitSessionsService: VisitSessionsService) {} | ||
|
||
public view(): RequestHandler { | ||
return async (req, res) => { | ||
const { prisoner, selectedVisitors } = req.session.bookingJourney | ||
const { prison, prisoner, selectedVisitors } = req.session.bookingJourney | ||
|
||
const selectedVisitorIds = selectedVisitors.map(visitor => visitor.personId) | ||
|
||
const visitSessions = await this.visitSessionsService.getVisitSessions( | ||
const visitSessionsCalendar = await this.visitSessionsService.getVisitSessionsCalendar( | ||
prisoner.prisonCode, | ||
prisoner.prisonerNumber, | ||
selectedVisitorIds, | ||
prison.policyNoticeDaysMax, | ||
) | ||
|
||
res.render('pages/bookingJourney/selectVisitDateTime', { | ||
booker: req.session.booker, | ||
bookingJourney: req.session.bookingJourney, | ||
visitSessions, | ||
calendarData, | ||
visitSessionsCalendar, | ||
}) | ||
} | ||
} | ||
|
||
public submit(): RequestHandler { | ||
return async (req, res) => { | ||
const { visitSlot } = req.body | ||
|
||
const sessionDate = visitSlot.split('_')[0] | ||
const sessionTemplateReference = visitSlot.split('_')[1] | ||
|
||
return res.send( | ||
`<pre>Visit slot selected:\n\nsessionDate: ${sessionDate}\n\nsessionTemplateReference: ${sessionTemplateReference}</pre>`, | ||
Check failure Code scanning / CodeQL Reflected cross-site scripting High
Cross-site scripting vulnerability due to a
user-provided value Error loading related location Loading |
||
) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.