11module . exports = router => {
22
3- router . get ( '/regions/v1 ' , ( req , res ) => {
3+ router . get ( '/regions' , ( req , res ) => {
44 const data = req . session . data
55 const organisations = data . organisations . filter ( ( organisation ) => ( organisation . region === "Y61" ) && ( organisation . status != "Closed" ) )
66
77 const closedOrganisationsCount = data . organisations . filter ( ( organisation ) => ( organisation . region === "Y61" && organisation . status == "Closed" ) ) . length
88
9- res . render ( 'regions/v1/ index' , {
9+ res . render ( 'regions/index' , {
1010 organisations,
1111 closedOrganisationsCount
1212 } )
1313 } )
1414
15- router . get ( '/regions/v1/ organisations/closed' , ( req , res ) => {
15+ router . get ( '/regions/organisations/closed' , ( req , res ) => {
1616 const data = req . session . data
1717 const organisations = data . organisations . filter ( ( organisation ) => ( organisation . region === "Y61" && organisation . status == "Closed" ) )
1818
19- res . render ( 'regions/v1/ closed-organisations' , {
19+ res . render ( 'regions/closed-organisations' , {
2020 organisations
2121 } )
2222 } )
2323
2424 // Inviting an organisation
25- router . post ( '/regions/v1/ add' , ( req , res ) => {
25+ router . post ( '/regions/add' , ( req , res ) => {
2626
2727 const organisationCode = req . session . data . organisationCode
2828 const addedUserId = Math . floor ( Math . random ( ) * 10000000 ) . toString ( )
@@ -78,10 +78,10 @@ module.exports = router => {
7878 req . session . data . firstName = ''
7979 req . session . data . lastName = ''
8080
81- res . redirect ( '/regions/v1/ organisations/' + organisationCode )
81+ res . redirect ( '/regions/organisations/' + organisationCode )
8282 } )
8383
84- router . get ( '/regions/v1/ organisation-details' , ( req , res ) => {
84+ router . get ( '/regions/organisation-details' , ( req , res ) => {
8585 const organisationCode = req . session . data . organisationCode
8686
8787 let organisationName , organisationLine1 , organisationTown , organisationPostcode , organisationType , legallyClosed
@@ -114,12 +114,12 @@ module.exports = router => {
114114 legallyClosed : legallyClosed
115115 }
116116
117- res . render ( 'regions/v1/ organisation-details' , {
117+ res . render ( 'regions/organisation-details' , {
118118 organisation
119119 } )
120120 } )
121121
122- router . get ( '/regions/v1/ add-email' , ( req , res ) => {
122+ router . get ( '/regions/add-email' , ( req , res ) => {
123123 const organisationCode = req . session . data . organisationCode
124124
125125 let organisationName , organisationLine1 , organisationTown , organisationPostcode , organisationType
@@ -149,12 +149,12 @@ module.exports = router => {
149149 }
150150 }
151151
152- res . render ( 'regions/v1/ add-email' , {
152+ res . render ( 'regions/add-email' , {
153153 organisation
154154 } )
155155 } )
156156
157- router . get ( '/regions/v1/ check-and-send' , ( req , res ) => {
157+ router . get ( '/regions/check-and-send' , ( req , res ) => {
158158 const organisationCode = req . session . data . organisationCode
159159
160160 let organisationName , organisationLine1 , organisationTown , organisationPostcode , organisationType
@@ -184,16 +184,16 @@ module.exports = router => {
184184 }
185185 }
186186
187- res . render ( 'regions/v1/ check-and-send' , {
187+ res . render ( 'regions/check-and-send' , {
188188 organisation
189189 } )
190190 } )
191191
192192 // Inviting a second lead user for an organisation
193- router . post ( '/regions/v1/ organisations/:id/add' , ( req , res ) => {
193+ router . post ( '/regions/organisations/:id/add' , ( req , res ) => {
194194 const data = req . session . data
195195 const organisation = data . organisations . find ( ( org ) => org . id === req . params . id )
196- if ( ! organisation ) { res . redirect ( '/regions/v1/ ' ) ; return }
196+ if ( ! organisation ) { res . redirect ( '/regions/' ) ; return }
197197
198198 const addedUserId = Math . floor ( Math . random ( ) * 10000000 ) . toString ( )
199199
@@ -218,141 +218,141 @@ module.exports = router => {
218218 req . session . data . firstName = ''
219219 req . session . data . lastName = ''
220220
221- res . redirect ( '/regions/v1/ organisations/' + organisation . id )
221+ res . redirect ( '/regions/organisations/' + organisation . id )
222222 } )
223223
224224 // Viewing an organisation
225- router . get ( '/regions/v1/ organisations/:id' , ( req , res ) => {
225+ router . get ( '/regions/organisations/:id' , ( req , res ) => {
226226 const data = req . session . data
227227 const id = req . params . id
228228 const organisation = data . organisations . find ( ( org ) => org . id === id )
229- if ( ! organisation ) { res . redirect ( '/regions/v1/ ' ) ; return }
229+ if ( ! organisation ) { res . redirect ( '/regions/' ) ; return }
230230
231231 const users = data . users . filter ( ( user ) => ( user . organisations || [ ] ) . find ( ( organisation ) => organisation . id === id ) )
232232
233233
234- res . render ( 'regions/v1/ organisation' , {
234+ res . render ( 'regions/organisation' , {
235235 organisation,
236236 users
237237 } )
238238 } )
239239
240240 // Delete an organisation confirmation page
241- router . get ( '/regions/v1/ organisations/:id/delete' , ( req , res ) => {
241+ router . get ( '/regions/organisations/:id/delete' , ( req , res ) => {
242242 const organisation = req . session . data . organisations . find ( ( org ) => org . id === req . params . id )
243- if ( ! organisation ) { res . redirect ( '/regions/v1/ ' ) ; return }
243+ if ( ! organisation ) { res . redirect ( '/regions/' ) ; return }
244244
245- res . render ( 'regions/v1/ delete-organisation' , {
245+ res . render ( 'regions/delete-organisation' , {
246246 organisation
247247 } )
248248 } )
249249
250250 // Deleting an organisation
251- router . post ( '/regions/v1/ organisations/:id/deleted' , ( req , res ) => {
251+ router . post ( '/regions/organisations/:id/deleted' , ( req , res ) => {
252252 const organisation = req . session . data . organisations . find ( ( org ) => org . id === req . params . id )
253- if ( ! organisation ) { res . redirect ( '/regions/v1/ ' ) ; return }
253+ if ( ! organisation ) { res . redirect ( '/regions/' ) ; return }
254254
255255 // Remove organisation
256256 req . session . data . organisations . splice ( req . session . data . organisations . indexOf ( organisation ) , 1 )
257257
258- res . redirect ( '/regions/v1 ' )
258+ res . redirect ( '/regions' )
259259 } )
260260
261261 // Add another lead user to an organisation form
262- router . get ( '/regions/v1/ organisations/:id/add-email' , ( req , res ) => {
262+ router . get ( '/regions/organisations/:id/add-email' , ( req , res ) => {
263263 const data = req . session . data
264264 const organisation = data . organisations . find ( ( org ) => org . id === req . params . id )
265- if ( ! organisation ) { res . redirect ( '/regions/v1/ ' ) ; return }
265+ if ( ! organisation ) { res . redirect ( '/regions/' ) ; return }
266266
267- res . render ( 'regions/v1/ add-another-email' , {
267+ res . render ( 'regions/add-another-email' , {
268268 organisation
269269 } )
270270 } )
271271
272272 // Deactivate an organisation
273- router . get ( '/regions/v1/ organisations/:id/deactivate' , ( req , res ) => {
273+ router . get ( '/regions/organisations/:id/deactivate' , ( req , res ) => {
274274 const data = req . session . data
275275 const organisation = data . organisations . find ( ( org ) => org . id === req . params . id )
276- if ( ! organisation ) { res . redirect ( '/regions/v1/ ' ) ; return }
276+ if ( ! organisation ) { res . redirect ( '/regions/' ) ; return }
277277
278- res . render ( 'regions/v1/ deactivate' , {
278+ res . render ( 'regions/deactivate' , {
279279 organisation
280280 } )
281281 } )
282282
283283 // Deactivating an organisation
284- router . post ( '/regions/v1/ organisations/:id/deactivated' , ( req , res ) => {
284+ router . post ( '/regions/organisations/:id/deactivated' , ( req , res ) => {
285285 const organisation = req . session . data . organisations . find ( ( org ) => org . id === req . params . id )
286- if ( ! organisation ) { res . redirect ( '/regions/v1/ ' ) ; return }
286+ if ( ! organisation ) { res . redirect ( '/regions/' ) ; return }
287287
288288 organisation . status = "Deactivated"
289289
290- res . redirect ( '/regions/v1/ organisations/' + organisation . id )
290+ res . redirect ( '/regions/organisations/' + organisation . id )
291291 } )
292292
293293 // Reactivate an organisation
294- router . get ( '/regions/v1/ organisations/:id/reactivate' , ( req , res ) => {
294+ router . get ( '/regions/organisations/:id/reactivate' , ( req , res ) => {
295295 const data = req . session . data
296296 const organisation = data . organisations . find ( ( org ) => org . id === req . params . id )
297- if ( ! organisation ) { res . redirect ( '/regions/v1/ ' ) ; return }
297+ if ( ! organisation ) { res . redirect ( '/regions/' ) ; return }
298298
299- res . render ( 'regions/v1/ reactivate' , {
299+ res . render ( 'regions/reactivate' , {
300300 organisation
301301 } )
302302 } )
303303
304304 // Reactivating an organisation
305- router . post ( '/regions/v1/ organisations/:id/reactivated' , ( req , res ) => {
305+ router . post ( '/regions/organisations/:id/reactivated' , ( req , res ) => {
306306 const organisation = req . session . data . organisations . find ( ( org ) => org . id === req . params . id )
307- if ( ! organisation ) { res . redirect ( '/regions/v1/ ' ) ; return }
307+ if ( ! organisation ) { res . redirect ( '/regions/' ) ; return }
308308
309309 organisation . status = "Active"
310310
311- res . redirect ( '/regions/v1/ organisations/' + organisation . id )
311+ res . redirect ( '/regions/organisations/' + organisation . id )
312312 } )
313313
314314
315315 // Check a second lead user for an organisation
316- router . get ( '/regions/v1/ organisations/:id/add-email-check' , ( req , res ) => {
316+ router . get ( '/regions/organisations/:id/add-email-check' , ( req , res ) => {
317317 const data = req . session . data
318318 const organisation = data . organisations . find ( ( org ) => org . id === req . params . id )
319- if ( ! organisation ) { res . redirect ( '/regions/v1/ ' ) ; return }
319+ if ( ! organisation ) { res . redirect ( '/regions/' ) ; return }
320320
321- res . render ( 'regions/v1/ add-another-email-check' , {
321+ res . render ( 'regions/add-another-email-check' , {
322322 organisation
323323 } )
324324 } )
325325
326326 // Uninvite page for a user
327- router . get ( '/regions/v1/ organisations/:id/users/:userId/uninvite' , ( req , res ) => {
327+ router . get ( '/regions/organisations/:id/users/:userId/uninvite' , ( req , res ) => {
328328 const data = req . session . data
329329 const organisation = data . organisations . find ( ( org ) => org . id === req . params . id )
330- if ( ! organisation ) { res . redirect ( '/regions/v1/ ' ) ; return }
330+ if ( ! organisation ) { res . redirect ( '/regions/' ) ; return }
331331
332332 const user = data . users . find ( ( user ) => user . id === req . params . userId )
333333
334334 const userOrganisationSettings = ( user . organisations || [ ] ) . find ( ( organisation ) => organisation . id === organisation . id )
335335
336- // if (!user || userOrganisationSettings.status == 'Active') { res.redirect(`/regions/v1/ organisations/${organisation.id}`); return }
336+ // if (!user || userOrganisationSettings.status == 'Active') { res.redirect(`/regions/organisations/${organisation.id}`); return }
337337
338338 const numberOfActiveUsers = data . users . filter ( ( user ) => ( user . organisations || [ ] ) . find ( ( orgSetting ) => ( orgSetting . id === organisation . id ) && ( orgSetting . status === 'Active' ) ) ) . length
339339
340- res . render ( 'regions/v1/ uninvite' , {
340+ res . render ( 'regions/uninvite' , {
341341 organisation,
342342 user,
343343 numberOfActiveUsers
344344 } )
345345 } )
346346
347347 // Uninvite a user
348- router . post ( '/regions/v1/ organisations/:id/users/:userId/uninvited' , ( req , res ) => {
348+ router . post ( '/regions/organisations/:id/users/:userId/uninvited' , ( req , res ) => {
349349 const data = req . session . data
350350 const { id, userId } = req . params ;
351351 const organisation = data . organisations . find ( ( org ) => org . id === req . params . id )
352- if ( ! organisation ) { res . redirect ( '/regions/v1/ ' ) ; return }
352+ if ( ! organisation ) { res . redirect ( '/regions/' ) ; return }
353353
354354 const user = data . users . find ( ( user ) => user . id === userId )
355- if ( ! user ) { res . redirect ( `/regions/v1/ organisations/${ organisation . id } ` ) ; return }
355+ if ( ! user ) { res . redirect ( `/regions/organisations/${ organisation . id } ` ) ; return }
356356
357357 const organisationSetting = user . organisations . find ( ( org ) => org . id === id )
358358
@@ -364,9 +364,9 @@ module.exports = router => {
364364 // Remove the organisation if no lead users are left
365365 if ( numberOfUsersAtOrganisation === 0 ) {
366366 data . organisations . splice ( data . organisations . indexOf ( organisation ) , 1 )
367- res . redirect ( '/regions/v1/ ' )
367+ res . redirect ( '/regions/' )
368368 } else {
369- res . redirect ( '/regions/v1/ organisations/' + organisation . id )
369+ res . redirect ( '/regions/organisations/' + organisation . id )
370370 }
371371
372372 } )
0 commit comments