@@ -7,7 +7,7 @@ module.exports = router => {
77
88 const organisations = data . organisations . filter ( ( organisation ) => ( organisation . region === currentRegion . id ) && ( [ "Active" , "Invited" , "Deactivated" ] . includes ( organisation . status ) ) )
99
10- const closedOrganisationsCount = data . organisations . filter ( ( organisation ) => ( organisation . region === "Y61" && organisation . status == "Closed" ) ) . length
10+ const closedOrganisationsCount = data . organisations . filter ( ( organisation ) => ( organisation . region === currentRegion . id && organisation . status == "Closed" ) ) . length
1111
1212 res . render ( 'regions/index' , {
1313 organisations,
@@ -28,7 +28,7 @@ module.exports = router => {
2828
2929 router . get ( '/regions/review/:id' , ( req , res ) => {
3030 const data = req . session . data
31- const organisation = data . organisations . find ( ( org ) => org . id === req . params . id )
31+ const organisation = data . allOrganisations . find ( ( org ) => org . id === req . params . id )
3232
3333 res . render ( 'regions/organisation-request' , {
3434 organisation
@@ -37,7 +37,7 @@ module.exports = router => {
3737
3838 router . get ( '/regions/accept/:id' , ( req , res ) => {
3939 const data = req . session . data
40- const organisation = data . organisations . find ( ( org ) => org . id === req . params . id )
40+ const organisation = data . allOrganisations . find ( ( org ) => org . id === req . params . id )
4141
4242 res . render ( 'regions/accept' , {
4343 organisation
@@ -46,49 +46,33 @@ module.exports = router => {
4646
4747 // Inviting an organisation
4848 router . post ( '/regions/add' , ( req , res ) => {
49+ const data = req . session . data
50+ const currentRegion = res . locals . currentRegion
4951
50- const organisationCode = req . session . data . organisationCode
51- const addedUserId = Math . floor ( Math . random ( ) * 10000000 ) . toString ( )
52-
53- let organisationName , organisationLine1 , organisationTown , organisationPostcode , organisationType
52+ const organisationId = data . organisationId
53+ const organisation = data . allOrganisations . find ( ( org ) => org . id === organisationId )
5454
55- if ( organisationCode . startsWith ( 'FA' ) ) {
56- organisationName = req . session . data . nhsPharmacies [ organisationCode ] . name
57- organisationLine1 = req . session . data . nhsPharmacies [ organisationCode ] . address
58- organisationTown = req . session . data . nhsPharmacies [ organisationCode ] . town
59- organisationPostcode = req . session . data . nhsPharmacies [ organisationCode ] . postcode
60- organisationType = 'Community Pharmacy'
61- } else {
62- organisationName = req . session . data . nhsTrusts [ organisationCode ]
63- organisationLine1 = 'Cobbett House, Oxford Road'
64- organisationTown = 'Manchester'
65- organisationPostcode = 'M13 9WL'
66- organisationType = 'NHS Trust'
67- }
55+ const addedUserId = Math . floor ( Math . random ( ) * 10000000 ) . toString ( )
6856
6957 // Add organisation
7058 req . session . data . organisations . push ( {
71- id : req . session . data . organisationCode ,
72- name : organisationName ,
73- address : {
74- line1 : organisationLine1 ,
75- town : organisationTown ,
76- postcode : organisationPostcode
77- } ,
78- type : organisationType ,
59+ id : organisation . id ,
60+ name : organisation . name ,
61+ address : organisation . address ,
62+ type : organisation . type ,
7963 status : 'Invited' ,
80- region : "Y61"
64+ region : currentRegion . id
8165 } )
8266
8367 req . session . data . users . push ( {
8468 id : addedUserId ,
8569 email : req . session . data . email ,
8670 status : 'Invited' ,
87- firstName : req . session . data . firstName ,
88- lastName : req . session . data . lastName ,
71+ firstName : data . firstName ,
72+ lastName : data . lastName ,
8973 organisations : [
9074 {
91- id : req . session . data . organisationCode ,
75+ id : organisation . id ,
9276 status : "Invited" ,
9377 permissionLevel : "Lead administrator"
9478 }
@@ -97,115 +81,38 @@ module.exports = router => {
9781
9882 // Remove data from adding organisation flow
9983 req . session . data . email = ''
100- req . session . data . organisationCode = ''
84+ req . session . data . organisationId = ''
10185 req . session . data . firstName = ''
10286 req . session . data . lastName = ''
10387
104- res . redirect ( '/regions/organisations/' + organisationCode )
88+ res . redirect ( '/regions/organisations/' + organisationId )
10589 } )
10690
10791 router . get ( '/regions/organisation-details' , ( req , res ) => {
108- const organisationCode = req . session . data . organisationCode
109-
110- let organisationName , organisationLine1 , organisationTown , organisationPostcode , organisationType , legallyClosed
111-
112- if ( organisationCode . startsWith ( 'FA' ) ) {
113- organisationName = req . session . data . nhsPharmacies [ organisationCode ] . name
114- organisationLine1 = req . session . data . nhsPharmacies [ organisationCode ] . address
115- organisationTown = req . session . data . nhsPharmacies [ organisationCode ] . town
116- organisationPostcode = req . session . data . nhsPharmacies [ organisationCode ] . postcode
117- legallyClosed = req . session . data . nhsPharmacies [ organisationCode ] . legallyClosed
118- organisationType = 'Community Pharmacy'
119- } else {
120- organisationName = req . session . data . nhsTrusts [ organisationCode ]
121- legallyClosed = false
122- organisationLine1 = 'Cobbett House, Oxford Road'
123- organisationTown = 'Manchester'
124- organisationPostcode = 'M13 9WL'
125- organisationType = 'NHS Trust'
126- }
127-
128- const organisation = {
129- code : organisationCode ,
130- name : organisationName ,
131- type : organisationType ,
132- address : {
133- line1 : organisationLine1 ,
134- town : organisationTown ,
135- postcode : organisationPostcode
136- } ,
137- legallyClosed : legallyClosed
138- }
92+ const data = req . session . data
93+ const organisationId = data . organisationId
94+ const organisation = data . allOrganisations . find ( ( organisation ) => organisation . id === organisationId )
13995
14096 res . render ( 'regions/organisation-details' , {
14197 organisation
14298 } )
14399 } )
144100
145101 router . get ( '/regions/add-email' , ( req , res ) => {
146- const organisationCode = req . session . data . organisationCode
147-
148- let organisationName , organisationLine1 , organisationTown , organisationPostcode , organisationType
149-
150- if ( organisationCode . startsWith ( 'FA' ) ) {
151- organisationName = req . session . data . nhsPharmacies [ organisationCode ] . name
152- organisationLine1 = req . session . data . nhsPharmacies [ organisationCode ] . address
153- organisationTown = req . session . data . nhsPharmacies [ organisationCode ] . town
154- organisationPostcode = req . session . data . nhsPharmacies [ organisationCode ] . postcode
155- organisationType = 'Community Pharmacy'
156- } else {
157- organisationName = req . session . data . nhsTrusts [ organisationCode ]
158- organisationLine1 = 'Cobbett House, Oxford Road'
159- organisationTown = 'Manchester'
160- organisationPostcode = 'M13 9WL'
161- organisationType = 'NHS Trust'
162- }
163-
164- const organisation = {
165- id : organisationCode ,
166- name : organisationName ,
167- type : organisationType ,
168- address : {
169- line1 : organisationLine1 ,
170- town : organisationTown ,
171- postcode : organisationPostcode
172- }
173- }
102+ const data = req . session . data
103+ const organisationId = data . organisationId
104+ const organisation = data . allOrganisations . find ( ( organisation ) => organisation . id === organisationId )
174105
175106 res . render ( 'regions/add-email' , {
176107 organisation
177108 } )
178109 } )
179110
180111 router . get ( '/regions/check-and-send' , ( req , res ) => {
181- const organisationCode = req . session . data . organisationCode
182-
183- let organisationName , organisationLine1 , organisationTown , organisationPostcode , organisationType
184-
185- if ( organisationCode . startsWith ( 'FA' ) ) {
186- organisationName = req . session . data . nhsPharmacies [ organisationCode ] . name
187- organisationLine1 = req . session . data . nhsPharmacies [ organisationCode ] . address
188- organisationTown = req . session . data . nhsPharmacies [ organisationCode ] . town
189- organisationPostcode = req . session . data . nhsPharmacies [ organisationCode ] . postcode
190- organisationType = 'Community Pharmacy'
191- } else {
192- organisationName = req . session . data . nhsTrusts [ organisationCode ]
193- organisationLine1 = '73 Roman Rd'
194- organisationTown = 'Leeds'
195- organisationPostcode = 'LS2 5ZN'
196- organisationType = 'NHS Trust'
197- }
112+ const data = req . session . data
113+ const organisationId = data . organisationId
114+ const organisation = data . allOrganisations . find ( ( organisation ) => organisation . id === organisationId )
198115
199- const organisation = {
200- id : organisationCode ,
201- name : organisationName ,
202- type : organisationType ,
203- address : {
204- line1 : organisationLine1 ,
205- town : organisationTown ,
206- postcode : organisationPostcode
207- }
208- }
209116
210117 res . render ( 'regions/check-and-send' , {
211118 organisation
0 commit comments