Skip to content

Commit

Permalink
Fix issue of facilities not appearing in the linked facilities list
Browse files Browse the repository at this point in the history
  • Loading branch information
ertush committed Jul 17, 2024
1 parent c0545d6 commit b9d473c
Showing 1 changed file with 26 additions and 5 deletions.
31 changes: 26 additions & 5 deletions pages/community-units/edit/[id].js
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,38 @@ export async function getServerSideProps(ctx) {
case "facilities":

// page_size=${count > 500 ? '500' : count}& ; For limiting number of CHUs
const params = response?.cu !== undefined ? `?ward=${response?.cu?.geo_features?.properties?.ward}&fields=id,name,county,sub_county_name,constituency,ward_name` : '?fields=id,name,county,sub_county_name,constituency,ward_name';
const url = `${process.env.NEXT_PUBLIC_API_URL}/common/sub_counties/?name=${response?.cu?.facility_subcounty.split(' ').join('+')}`

const facilities = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/facilities/facilities/${params}&reporting_in_dhis=true&owner_type=6a833136-5f50-46d9-b1f9-5f961a42249f`,{
fetch(url, {
headers:{
'Authorization': 'Bearer ' + token,
'Accept': 'application/json'
'Accept': 'application/json',
'Authorization': `Bearer ${token}`
}
})
.then(async (resp) => {

if(resp.ok) {

const results = await resp.json()

const params = `?sub_county=${results?.results[0].id}&fields=id,name,county,sub_county_name,constituency,ward_name`

const facilities = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/facilities/facilities/${params}&reporting_in_dhis=true&owner_type=6a833136-5f50-46d9-b1f9-5f961a42249f`,{
headers:{
'Authorization': 'Bearer ' + token,
'Accept': 'application/json'
}

})

response["facilities"] = (await (await facilities.json()))?.results?.map(({ id, name }) => ({ label: name, value: id }))

}

})
.catch(e => console.error('Error: ', e.message))

response["facilities"] = (await (await facilities.json()))?.results?.map(({ id, name }) => ({ label: name, value: id }))

break;

case "contact_types":
Expand Down

0 comments on commit b9d473c

Please sign in to comment.