Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sdci 114 #169

Merged
merged 3 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions backend/src/components/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,12 @@ function createSchoolCache(schoolData, schoolGrades) {
return school;
});
}

function isActiveEntity(effective, expiry) {
let today = new Date();
return today > new Date(effective) && (!expiry || today < new Date(expiry));
}

module.exports = {
addFundingGroups,
filterByOpenedAndClosedDate,
Expand All @@ -507,4 +513,5 @@ module.exports = {
createSchoolCache,
formatGrades,
rearrangeAndRelabelObjectProperties,
isActiveEntity,
};
68 changes: 44 additions & 24 deletions backend/src/routes/authority-router.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const {
appendMailingAddressDetailsAndRemoveAddresses,
rearrangeAndRelabelObjectProperties,
sortByProperty,
isActiveEntity,
} = require("../components/utils.js");
//Batch Routes
router.get("/all-mailing/:type", checkToken, getAllAuthorityMailing);
Expand Down Expand Up @@ -87,34 +88,13 @@ async function getAllAuthorityMailing(req, res) {
log.error("getData Error", e.response ? e.response.status : e.message);
}
}
async function getDistrictCodes(req) {
if (!listCache.has("districtCodesList")) {
const url = `${config.get(
"server:instituteAPIURL"
)}/institute/authority-contact-type-codes`; // Update the URL according to your API endpoint
try {
const response = await axios.get(url, {
headers: { Authorization: `Bearer ${req.accessToken}` },
});
const districtCodeList = response.data;
listCache.set("districtCodesList", districtCodeList);
return districtCodeList;
} catch (e) {
log.error(
"getDistrictList Error",
e.response ? e.response.status : e.message
);
}
} else {
const districtCodeList = await listCache.get("districtCodesList");
return districtCodeList;
}
}

async function getAuthority(req, res) {
const { id } = req.params;
let currentDate = new Date().toISOString().substring(0, 19);
const params = [
{
condition: null,
condition: "AND",
searchCriteriaList: [
{
key: "independentAuthorityId",
Expand All @@ -125,6 +105,37 @@ async function getAuthority(req, res) {
},
],
},
{
condition: "AND",
searchCriteriaList: [
{
key: "closedDate",
operation: "eq",
value: null,
valueType: "STRING",
condition: "OR",
},
{
key: "closedDate",
operation: "gte",
value: currentDate,
valueType: "DATE_TIME",
condition: "OR",
},
],
},
{
condition: "AND",
searchCriteriaList: [
{
key: "openedDate",
operation: "lte",
value: currentDate,
valueType: "DATE_TIME",
condition: "AND",
},
],
},
];

const jsonString = JSON.stringify(params);
Expand All @@ -142,6 +153,14 @@ async function getAuthority(req, res) {
headers: { Authorization: `Bearer ${req.accessToken}` },
});

// Filter Authority Contacts
const filteredAuthorityContacts =
authorityDataResponse?.data?.contacts?.filter((contact) =>
isActiveEntity(contact.effectiveDate, contact.expiryDate)
);
// Overwrite Authority Contacts
authorityDataResponse.data.contacts = filteredAuthorityContacts;

const authoritySchoolsResponse = await axios.get(authoritySchoolsUrl, {
headers: { Authorization: `Bearer ${req.accessToken}` },
});
Expand All @@ -162,6 +181,7 @@ async function getAuthority(req, res) {
openedDate < today
);
});

const authorityJSON = {
authorityData: authorityDataResponse.data,
authoritySchools: filteredSchoolsResponse,
Expand Down
41 changes: 33 additions & 8 deletions backend/src/routes/district-router.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,9 +330,10 @@ async function getAllDistrictMailing(req, res) {
async function getDistrict(req, res) {
const { id } = req.params;

let currentDate = new Date().toISOString().substring(0, 19);
const params = [
{
condition: null,
condition: "AND",
searchCriteriaList: [
{
key: "districtID",
Expand All @@ -341,13 +342,6 @@ async function getDistrict(req, res) {
valueType: "UUID",
condition: "AND",
},
{
key: "closedDate",
operation: "eq",
value: null,
valueType: "STRING",
condition: "AND",
},
{
key: "schoolCategoryCode",
operation: "neq",
Expand All @@ -371,6 +365,37 @@ async function getDistrict(req, res) {
},
],
},
{
condition: "AND",
searchCriteriaList: [
{
key: "closedDate",
operation: "eq",
value: null,
valueType: "STRING",
condition: "OR",
},
{
key: "closedDate",
operation: "gte",
value: currentDate,
valueType: "DATE_TIME",
condition: "OR",
},
],
},
{
condition: "AND",
searchCriteriaList: [
{
key: "openedDate",
operation: "lte",
value: currentDate,
valueType: "DATE_TIME",
condition: "AND",
},
],
},
];

const jsonString = JSON.stringify(params);
Expand Down
49 changes: 30 additions & 19 deletions backend/src/routes/school-router.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ const {
sortJSONBySchoolCode,
rearrangeAndRelabelObjectProperties,
filterByPubliclyAvailableCodes,
addFundingGroups
addFundingGroups,
isActiveEntity,
} = require("../components/utils");
const { checkToken } = require("../components/auth");
const { schoolCache, listCache, codeCache } = require("../components/cache");
Expand Down Expand Up @@ -167,6 +168,7 @@ async function getSchool(req, res) {
expiryDate: "2099-12-31T00:00:00",
},
];

const schoolData = response.data;

const includedFields = ["label", "description"];
Expand All @@ -177,7 +179,6 @@ async function getSchool(req, res) {
(info) => info.publiclyAvailable === true,
includedFields
);


schoolData.contacts = filterByPubliclyAvailableCodes(
schoolData.contacts,
Expand All @@ -186,26 +187,27 @@ async function getSchool(req, res) {
contactTypeCodes.codesList.schoolContactTypeCodes,
"schoolContactTypeCode"
)
);
).filter((contact) =>
isActiveEntity(contact.effectiveDate, contact.expiryDate)
); // Filter out inactive contacts
schoolData.contacts = filterByExpiryDate(schoolData.contacts);
const formattedGrades = formatGrades(schoolData.grades, schoolGrades);
const schoolWithFormattedGrades = [{ ...schoolData, ...formattedGrades }];

const schoolsWithFundingGroups = addFundingGroups(schoolWithFormattedGrades, fundingGroups)

const schoolsWithFundingGroups = addFundingGroups(
schoolWithFormattedGrades,
fundingGroups
);
res.json(schoolsWithFundingGroups[0]);

})
.catch((e) => {
log.error("getSchools Error", e.response ? e.response.status : e.message);
});
}
async function getAllSchoolMailing(req, res) {
const allSchools = await getAllSchools(req, res);
res.json(allSchools);
}

async function getAllSchools(req, res) {
const { schoolCategory } = req.params;
const contactTypeCodes = await listCache.get("codesList");
//const contactTypeCodes = await listCache.get("codesList");
let params = [];

if (await !schoolCache.has("openschoollist" + schoolCategory)) {
Expand Down Expand Up @@ -286,7 +288,7 @@ async function getAllSchools(req, res) {
{ property: "physical_addressLine1", label: "Physical Address" },
{ property: "physical_city", label: "Physical City" },
{ property: "physical_provinceCode", label: "Physical Province" },
{ property: "physical_postal", label: "Physical Postal Code" },
{ property: "physical_postal", label: "Physical Postal Code" },
{ property: "firstName", label: "Principal First Name" },
{ property: "lastName", label: "Principal Last Name" },
{ property: "facilityTypeCode", label: "Type" },
Expand Down Expand Up @@ -315,9 +317,18 @@ async function getAllSchools(req, res) {
{ property: "GRADE11", label: "Grade 11 Enrollment" },
{ property: "GRADE12", label: "Grade 12 Enrollment" },
{ property: "primaryK3", label: "Group Classification Primary K-3" },
{ property: "elementary47", label: "Group Classification Elementary 4-7 EU" },
{ property: "juniorSecondary810", label: "Group Classification Junior Secondary 8-10 SU" },
{ property: "seniorSecondary1112", label: "Group Classification Senior Secondary 11-12" },
{
property: "elementary47",
label: "Group Classification Elementary 4-7 EU",
},
{
property: "juniorSecondary810",
label: "Group Classification Junior Secondary 8-10 SU",
},
{
property: "seniorSecondary1112",
label: "Group Classification Senior Secondary 11-12",
},
];
const mailingListpropertyOrder = [
{ property: "districtNumber", label: "District Number" },
Expand All @@ -343,8 +354,8 @@ async function getAllSchools(req, res) {
schoolGrades
)
);
openSchoolList = addFundingGroups(openSchoolListSorted, fundingGroups)

openSchoolList = addFundingGroups(openSchoolListSorted, fundingGroups);
let openSchoolMailingList = [...openSchoolList];

openSchoolList = normalizeJsonObject(
Expand All @@ -354,7 +365,7 @@ async function getAllSchools(req, res) {
null,
["label", "description"]
);

openSchoolList = normalizeJsonObject(
openSchoolList,
facilityCodes,
Expand Down Expand Up @@ -430,4 +441,4 @@ async function getAllSchools(req, res) {
}
}

module.exports = router;
module.exports = router;
Empty file removed backend/src/util/constants.js
Empty file.
Loading