Skip to content

Commit

Permalink
Merge pull request #336 from USEPA/feature/update-nces-data-lookup
Browse files Browse the repository at this point in the history
Feature/update nces data lookup
  • Loading branch information
courtneymyers authored Aug 18, 2023
2 parents 8d66ca0 + e583889 commit 15eca33
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions app/server/app/routes/formioNCES.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const data = require("../content/nces.json");
const router = express.Router();

// --- Search the NCES data with the provided NCES ID and return a match
router.get("/:searchText", async (req, res) => {
router.get("/:searchText?", async (req, res) => {
const { searchText } = req.params;

// const s3BucketUrl = `https://${S3_PUBLIC_BUCKET}.s3-${S3_PUBLIC_REGION}.amazonaws.com`;
Expand All @@ -22,11 +22,25 @@ router.get("/:searchText", async (req, res) => {
// : axios.get(`${s3BucketUrl}/content/nces.json`).then((res) => res.data))
// );

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 = data.find((item) => item["NCES District ID"] === searchText);

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

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

0 comments on commit 15eca33

Please sign in to comment.