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

fix grades and remove options #116

Merged
merged 1 commit into from
Nov 22, 2023
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
2 changes: 0 additions & 2 deletions backend/src/routes/district-router.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,6 @@ async function getDistrict(req, res) {
const contactTypeCodes = await getDistrictCodes(req);
const districtContactCodeTypes = await listCache.get("codesList")
const nonPublicContactTypeCodes = getNonPublicContactTypeCodes(contactTypeCodes);
console.log("REVIEW")
console.log(nonPublicContactTypeCodes)

const districtDataPublic = removeContacts(
districtDataResponse.data,
Expand Down
63 changes: 38 additions & 25 deletions backend/src/routes/institute-router.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const config = require("../config/index");

const axios = require("axios");
const { checkToken } = require("../components/auth");
const {removeFieldsByCriteria, createList, addDistrictLabels, districtNumberSort, isAllowedSchoolCategory } = require("../components/utils");
const {formatGrades, removeFieldsByCriteria, createList, addDistrictLabels, districtNumberSort, isAllowedSchoolCategory, filterRemoveByField } = require("../components/utils");
const { listCache, codeCache } = require("../components/cache");

const schoolListOptions = { fields: ["mincode", "displayName", "schoolId", "closedDate"], fieldToInclude: "closedDate", valueToInclude: null, sortField: "mincode" };
Expand Down Expand Up @@ -37,12 +37,13 @@ router.get("/authority/list", checkToken, getAuthorityList);
router.get("/district/list", checkToken, getDistrictList);
router.get("/district/contact/*", checkToken, getDistrictContactsAPI);
router.get("/create-cache", checkToken, createCache);
router.get("/category-codes", checkToken, getCategoryCodes);
router.get("/*", checkToken, getInstituteAPI);
async function createCache(req, res) {

if (!listCache.has("categoryCodes")) {
//const codes = [];

try {
const categoryCodesResponse = await axios.get(
`${config.get(
Expand All @@ -52,7 +53,10 @@ async function createCache(req, res) {
headers: { Authorization: `Bearer ${req.accessToken}` },
}
);

categoryCodesResponse.data = filterRemoveByField(categoryCodesResponse.data,"schoolCategoryCode", ["FED_BAND","POST_SEC","YUKON"])
listCache.set("categoryCodes", categoryCodesResponse.data);

} catch (error) {
const statusCode = error.response ? error.response.status : 500;
log.error("Category Code Caching Error", statusCode, error.message);
Expand Down Expand Up @@ -135,8 +139,6 @@ async function createCache(req, res) {


if (await !listCache.has("codesList")) {
//const codes = [];

try {
const authorityContactTypeCodesResponse = await axios.get(
`${config.get(
Expand Down Expand Up @@ -289,6 +291,13 @@ async function getOffshoreSchoolList(req, res) {
.get(url, { headers: { Authorization: `Bearer ${req.accessToken}` } })
.then((response) => {
const offshoreSchoolList = response.data.content;
const schoolGrades = codeCache.get("gradelist");

for (let i = 0; i < offshoreSchoolList.length; i++) {
const formattedGrades = formatGrades(offshoreSchoolList[i].grades, schoolGrades);
offshoreSchoolList[i] = { ...offshoreSchoolList[i], ...formattedGrades };
// Now you can use the updated offshoreSchoolList[i] object as needed
}
res.json(offshoreSchoolList);
listCache.set("offshoreschoollist", offshoreSchoolList);
log.info(req.url);
Expand Down Expand Up @@ -355,28 +364,32 @@ async function getAuthorityList(req, res) {
res.json(authorityList);
}
}
async function getOpenSchools(req, res) {
async function getCategoryCodes(req, res) {


if (await !listCache.has("openschoollist")) {
const url = `${config.get("server:instituteAPIURL")}/institute/school`; // Update the URL according to your API endpoint
axios
.get(url, { headers: { Authorization: `Bearer ${req.accessToken}` } })
.then((response) => {
const openSchoolList = createList(response.data, openSchoolListOptions);
res.json(openSchoolList);
listCache.set("openschoollist", openSchoolList);
log.info(req.url);
})
.catch((e) => {
log.error(
"getSchoolsList Error",
e.response ? e.response.status : e.message
);
});
} else {
const openSchoolList = await listCache.get("openschoollist");
res.json(openSchoolList);
if (!listCache.has("categoryCodes")) {
//const codes = [];

try {
const categoryCodesResponse = await axios.get(
`${config.get(
"server:instituteAPIURL"
)}/institute/category-codes`,
{
headers: { Authorization: `Bearer ${req.accessToken}` },
}
);

categoryCodesResponse.data = filterRemoveByField(categoryCodesResponse.data,"schoolCategoryCode", ["FED_BAND","POST_SEC","YUKON"])
listCache.set("categoryCodes", categoryCodesResponse.data);

} catch (error) {
const statusCode = error.response ? error.response.status : 500;
log.error("Category Code Caching Error", statusCode, error.message);
res.status(statusCode).send(error.message);
}
} else{
const categoryCodes = await listCache.get("categoryCodes");
res.json(categoryCodes)
}
}
async function getSchoolList(req, res) {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ const data = ref([]) // Placeholder for the received data
const appStore = useAppStore()

onBeforeMount(async () => {
await appStore.setCodes()
await appStore.setDistricts()
await appStore.setAuthorityList()
await appStore.setSchoolList()
await appStore.setOffshoreSchoolList()
await appStore.setCodes()
})
</script>

Expand Down
4 changes: 2 additions & 2 deletions frontend/src/stores/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ export const useAppStore = defineStore('app', {
})

},
setCodes(): void {
InstituteService.loadCache().then((response) => {
async setCodes(): void {
await InstituteService.loadCache().then((response) => {
console.log(response)
}).catch((error) => {
console.error("ERRPR LOADING CACHE" + error)
Expand Down