Skip to content

Commit

Permalink
Hotfix fixed issue of linked facility displaying
Browse files Browse the repository at this point in the history
  • Loading branch information
ertush committed Oct 25, 2024
1 parent cf4864b commit ae972c6
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 29 deletions.
6 changes: 4 additions & 2 deletions pages/community-units/[id].js
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,9 @@ export async function getServerSideProps (ctx) {
activity_log: []
}

const response = (() => fetch(`${process.env.NEXT_PUBLIC_API_URL}/chul/units/${queryId}/`, {
let response = {}

response = (() => fetch(`${process.env.NEXT_PUBLIC_API_URL}/chul/units/${queryId}/`, {
headers: {
'Accept': 'application/json',
'Authorization': `Bearer ${token}`
Expand Down Expand Up @@ -787,7 +789,7 @@ export async function getServerSideProps (ctx) {
})
.catch(e => {
console.error('Error when fetching props?.cu details for: ', queryId, e.message)
}))();
}))()


return {
Expand Down
18 changes: 11 additions & 7 deletions pages/community-units/add.js
Original file line number Diff line number Diff line change
Expand Up @@ -1369,14 +1369,16 @@ export async function getServerSideProps({req, res}) {



const userSubCountyID = resp?.user_sub_counties[0]?.sub_county
const userSubCountyIDs = resp?.user_sub_counties.length > 1 ? resp?.user_sub_counties.map(({sub_county}) => sub_county).join(',') : resp?.user_sub_counties[0]?.sub_county
const userCountyID = resp?.county
const userGroup = resp?.groups[0]?.id


if(userGroup == 2 && userSubCountyID){

const subCountyFacilitiesURL = `${process.env.NEXT_PUBLIC_API_URL}/facilities/facilities/?sub_county=${userSubCountyID}&reporting_in_dhis=true&closed=false&fields=id,name,county,sub_county_name,constituency,ward_name&page_size=300`
if(userGroup == 2 && userSubCountyIDs){

const subCountyFacilitiesURL = `${process.env.NEXT_PUBLIC_API_URL}/facilities/facilities/?sub_county=${userSubCountyIDs}&reporting_in_dhis=true&closed=false&fields=id,name,county,sub_county_name,constituency,ward_name&page_size=300`



return fetch(subCountyFacilitiesURL, {
headers:{
Expand Down Expand Up @@ -1486,15 +1488,17 @@ export async function getServerSideProps({req, res}) {

response['token'] = token

return {
props: response
}


}

catch(e) {
console.error(e.message)
}

return {
props: response
}

}

Expand Down
44 changes: 24 additions & 20 deletions pages/community-units/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -547,16 +547,20 @@ export async function getServerSideProps(ctx) {

async function fetchData(token) {
let filterQuery = JSON.parse(JSON.stringify(ctx.query));
delete filterQuery['sub_county']
console.log({filterQuery})

let qry = ''
let url

if (ctx.query !== null) {
qry = Object.keys(filterQuery).map(function (key) {
// if(key == 'sub_county') return
const er = `${key}=${filterQuery[key]}`
return er
}).join('&')

// console.log(qry);

url = `${process.env.NEXT_PUBLIC_API_URL}/chul/units/?${qry}&fields=id,code,name,status_name,facility_name,has_edits,facility_county,facility_subcounty,facility_ward,date_established`;
} else {
url = `${process.env.NEXT_PUBLIC_API_URL}/chul/units/?fields=id,code,name,status_name,date_established,facility,facility_name,facility_county,facility_subcounty,facility_ward,facility_constituency`;
Expand All @@ -569,28 +573,28 @@ export async function getServerSideProps(ctx) {
url += `&search=${query.searchTerm}`;
}

let other_posssible_filters = [
'county',
'constituency',
'ward',
'status',
'sub_county',
];

other_posssible_filters.map((flt) => {
if (ctx?.query[flt]) {
query[flt] = ctx?.query[flt];
url = url + '&' + flt.replace('chu_', '') + '=' + ctx?.query[flt];
}
});
// let other_posssible_filters = [
// 'county',
// 'constituency',
// 'ward',
// 'status',
// 'sub_county',
// ];

// other_posssible_filters.map((flt) => {
// if (ctx?.query[flt]) {
// query[flt] = ctx?.query[flt];
// url = url + '&' + flt.replace('chu_', '') + '=' + ctx?.query[flt];
// }
// });



let current_url = url + `&page_size=11000`;

if (ctx?.query?.page) {
url = `${url}&page=${ctx.query.page}`;
}
// if (ctx?.query?.page) {
// url = `${url}&page=${ctx.query.page}`;
// }


const {response: user} = await getUserDetails(token, `${process.env.NEXT_PUBLIC_API_URL}/rest-auth/user/`)
Expand All @@ -607,8 +611,8 @@ export async function getServerSideProps(ctx) {

} else if(userGroup === 2) { // SCHRIO

const userSubCountyID = user?.user_sub_counties[0]?.sub_county
url = `${url}&sub_county=${userSubCountyID}`
const userSubCountyIDs = user?.user_sub_counties.length > 1 ? user?.user_sub_counties?.map(({sub_county}) => sub_county)?.join(',') : user?.user_sub_counties[0]?.sub_county
url = `${url}&sub_county=${userSubCountyIDs}`

}

Expand Down

0 comments on commit ae972c6

Please sign in to comment.