Skip to content

Commit

Permalink
Add utility function for searching nces data, add nces routes to 2023…
Browse files Browse the repository at this point in the history
… and 2024 formio routes, and update 2024 nces data to latest version
  • Loading branch information
courtneymyers committed Aug 21, 2024
1 parent 7547071 commit 163f8c1
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 4 deletions.
29 changes: 28 additions & 1 deletion app/server/app/content/nces-2024.json
Original file line number Diff line number Diff line change
Expand Up @@ -526365,7 +526365,7 @@
"Longitude": "-64.944611"
},
{
"NCES ID": "A999999",
"NCES ID": "A999990",
"School District Name": "Morongo School",
"Physical Address Line 1": "12130 Santiago Road",
"Physical Address Line 2": "",
Expand Down Expand Up @@ -526633,5 +526633,32 @@
"County Number ": "Not in ELSI",
"Latitude": "Not in ELSI",
"Longitude": "Not in ELSI"
},
{
"NCES ID": "A999999",
"School District Name": "",
"Physical Address Line 1": "",
"Physical Address Line 2": "",
"Physical Address Line 3": "",
"Physical Address City": "",
"Physical Address State": "",
"Physical Address Zip": "00nan",
"LEA Charter Status": "",
"Agency Type": "",
"Locale Code": "",
"Percent of Students in Poverty": "",
"Is Prioritized": "",
"Prioritized for Poverty >20%": "",
"Prioritized for Rural 43": "",
"Prioritized for Impact Aid": "",
"Prioritized for BIE": "",
"Prioritized Tribal (Impact and BIE)": "",
"Self-Certify (Large Number of Students and/or Number of Schools": "",
"Self-Certify Large Number of Student": "",
"Self-Certify Large Number of Schools": "",
"County Name": "",
"County Number ": "",
"Latitude": "",
"Longitude": ""
}
]
2 changes: 1 addition & 1 deletion app/server/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ function fetchNcesData() {
* Cloud.gov: fetch files from the public s3 bucket
*/
return NODE_ENV === "development"
? readFile(localFilePath, "utf8")
? readFile(localFilePath, "utf8").then((string) => JSON.parse(string))
: axios.get(s3FileUrl).then((res) => res.data);
}),
)
Expand Down
7 changes: 7 additions & 0 deletions app/server/app/routes/formio2023.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ const {
verifyMongoObjectId,
} = require("../middleware");
const {
searchNcesData,
//
uploadS3FileMetadata,
downloadS3FileMetadata,
//
Expand Down Expand Up @@ -36,6 +38,11 @@ const router = express.Router();

router.use(ensureAuthenticated);

// --- search 2023 NCES data with the provided NCES ID and return a match
router.get("nces/:searchText", (req, res) => {
searchNcesData({ rebateYear, req, res });
});

// --- download Formio S3 file metadata
router.get(
"/s3/:formType/:mongoId/:comboKey/storage/s3",
Expand Down
7 changes: 7 additions & 0 deletions app/server/app/routes/formio2024.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ const {
verifyMongoObjectId,
} = require("../middleware");
const {
searchNcesData,
//
uploadS3FileMetadata,
downloadS3FileMetadata,
//
Expand Down Expand Up @@ -36,6 +38,11 @@ const router = express.Router();

router.use(ensureAuthenticated);

// --- search 2024 NCES data with the provided NCES ID and return a match
router.get("nces/:searchText", (req, res) => {
searchNcesData({ rebateYear, req, res });
});

// --- download Formio S3 file metadata
router.get(
"/s3/:formType/:mongoId/:comboKey/storage/s3",
Expand Down
2 changes: 1 addition & 1 deletion app/server/app/routes/formioNCES.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ router.get("/:searchText?", (req, res) => {
return res.json({});
}

const result = req.app.locals.nces["2023"].find((item) => {
const result = req.app.locals.nces[2023].find((item) => {
return item["NCES ID"] === searchText;
});

Expand Down
2 changes: 1 addition & 1 deletion app/server/app/routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ router.use("/api/content", require("./content"));
router.use("/api/user", require("./user"));
router.use("/api/config", require("./config"));
router.use("/api/bap", require("./bap"));
router.use("/api/formio/nces", require("./formioNCES"));
router.use("/api/formio/nces", require("./formioNCES")); // TODO: remove this route and file after NCES URL has been updated in 2022 FRF
router.use("/api/formio/2022", require("./formio2022"));
router.use("/api/formio/2023", require("./formio2023"));
router.use("/api/formio/2024", require("./formio2024"));
Expand Down
37 changes: 37 additions & 0 deletions app/server/app/utilities/formio.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,41 @@ const { NODE_ENV } = process.env;
* @typedef {'2022' | '2023' | '2024'} RebateYear
*/

/**
* @param {Object} param
* @param {RebateYear} param.rebateYear
* @param {express.Request} param.req
* @param {express.Response} param.res
*/
function searchNcesData({ rebateYear, req, res }) {
const { searchText } = req.params;

if (!searchText) {
const logMessage = `No NCES ID passed to NCES data lookup.`;
log({ level: "info", message: logMessage, req });

return res.json({});
}

if (searchText.length !== 7) {
const logMessage = `Invalid NCES ID '${searchText}' passed to NCES data lookup.`;
log({ level: "info", message: logMessage, req });

return res.json({});
}

const result = req.app.locals.nces[rebateYear].find((item) => {
return item["NCES ID"] === searchText;
});

const logMessage =
`${rebateYear} NCES data searched with NCES ID '${searchText}' resulting in ` +
`${result ? "a match" : "no matches"}.`;
log({ level: "info", message: logMessage, req });

return res.json({ ...result });
}

/**
* @param {Object} param
* @param {RebateYear} param.rebateYear
Expand Down Expand Up @@ -1847,6 +1882,8 @@ function fetchChangeRequest({ rebateYear, req, res }) {
}

module.exports = {
searchNcesData,
//
uploadS3FileMetadata,
downloadS3FileMetadata,
//
Expand Down

0 comments on commit 163f8c1

Please sign in to comment.