Skip to content

Commit

Permalink
Update NCES web service endpoint to account for no NCES ID provided a…
Browse files Browse the repository at this point in the history
…nd only perform the search if NCES ID is exactly seven characters
  • Loading branch information
courtneymyers committed Aug 18, 2023
1 parent 8d66ca0 commit e583889
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 e583889

Please sign in to comment.