Skip to content

Commit

Permalink
Merge pull request #166 from bcgov/sdci-113
Browse files Browse the repository at this point in the history
Inconsistent loading when navigating to District and Authority nodes via URL
  • Loading branch information
michaeltangbcgov authored May 23, 2024
2 parents 2fa81f5 + 98cfe30 commit 6ce9f13
Show file tree
Hide file tree
Showing 9 changed files with 459 additions and 387 deletions.
71 changes: 35 additions & 36 deletions backend/src/routes/district-router.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ async function getDistrictCodes(req) {
return districtCodeList;
} catch (e) {
log.error(
"getDistrictList Error",
"getDistrictCodesList Error",
e.response ? e.response.status : e.message
);
}
Expand Down Expand Up @@ -250,7 +250,6 @@ async function getAllDistrictContacts(req, res) {

async function getAllDistrictMailing(req, res) {
const districtList = await listCache.get("districtlist");
const contactTypeCodes = await listCache.get("codesList");

const propertyOrder = [
{ property: "districtId_districtNumber", label: "District Number" },
Expand Down Expand Up @@ -323,13 +322,11 @@ async function getAllDistrictMailing(req, res) {
const contentByDistrict = sortJSONByDistrictNumber(content);

res.json(contentByDistrict);
//res.json(districtContactsReorderedAndRelabeled );
} catch (e) {
log.error("getData Error", e.response ? e.response.status : e.message);
}
}

//api/v1/institute/district/12342525
async function getDistrict(req, res) {
const { id } = req.params;

Expand Down Expand Up @@ -399,8 +396,9 @@ async function getDistrict(req, res) {
const facilityCodes = await listCache.get("facilityCodes");
const fundingGroups = await listCache.get("fundingGroups");
const districtContactCodeTypes = await listCache.get("codesList");
const nonPublicContactTypeCodes =
getNonPublicContactTypeCodes(contactTypeCodes);
const nonPublicContactTypeCodes = await getNonPublicContactTypeCodes(
contactTypeCodes
);

const districtDataPublic = removeContacts(
districtDataResponse.data,
Expand All @@ -410,36 +408,37 @@ async function getDistrict(req, res) {
districtDataPublic,
contactTypeCodes
);
districtDataPublicWithLabels.contacts = filterByPubliclyAvailableCodes(
districtDataPublicWithLabels.contacts,
"districtContactTypeCode",
getArrayofPubliclyAvailableCodes(
districtContactCodeTypes.codesList.districtContactTypeCodes,
"districtContactTypeCode"
)
);
districtDataPublicWithLabels.contacts = filterByExpiryDate(
districtDataPublicWithLabels.contacts
);

districtSchoolsResponse.data.content = normalizeJsonObject(
districtSchoolsResponse.data.content,
schoolCategoryCodes,
"schoolCategoryCode",
null,
["label", "description"]
);
districtSchoolsResponse.data.content = normalizeJsonObject(
districtSchoolsResponse.data.content,
facilityCodes,
"faciltyTypeCode",
null,
["label", "description"]
);
districtSchoolsResponse.data.content = addFundingGroups(
districtSchoolsResponse.data.content,
fundingGroups
);
if (!!districtContactCodeTypes) {
districtDataPublicWithLabels.contacts = filterByPubliclyAvailableCodes(
districtDataPublicWithLabels.contacts,
"districtContactTypeCode",
getArrayofPubliclyAvailableCodes(
districtContactCodeTypes.codesList.districtContactTypeCodes,
"districtContactTypeCode"
)
);
districtDataPublicWithLabels.contacts = filterByExpiryDate(
districtDataPublicWithLabels.contacts
);
districtSchoolsResponse.data.content = normalizeJsonObject(
districtSchoolsResponse.data.content,
schoolCategoryCodes,
"schoolCategoryCode",
null,
["label", "description"]
);
districtSchoolsResponse.data.content = normalizeJsonObject(
districtSchoolsResponse.data.content,
facilityCodes,
"faciltyTypeCode",
null,
["label", "description"]
);
districtSchoolsResponse.data.content = addFundingGroups(
districtSchoolsResponse.data.content,
fundingGroups
);
}

const today = new Date();
const filteredSchoolsResponse = districtSchoolsResponse.data.content.filter(
Expand Down
Loading

0 comments on commit 6ce9f13

Please sign in to comment.