Skip to content

Fix attendance_app: await async readData() so /students and /download return data - #379

Open
eeshsaxena wants to merge 1 commit into
elevatebox:mainfrom
eeshsaxena:fix/attendance-app-await-readdata
Open

Fix attendance_app: await async readData() so /students and /download return data#379
eeshsaxena wants to merge 1 commit into
elevatebox:mainfrom
eeshsaxena:fix/attendance-app-await-readdata

Conversation

@eeshsaxena

Copy link
Copy Markdown

attendance_app/server.js reads students from MongoDB via readData(), which returns a find().toArray() promise. Two routes used it without awaiting:

  • GET /students did res.json(readData()), so it serialized a pending promise and returned {} instead of the student list.
  • GET /download did readData().map(...), which throws because a promise has no .map, so the CSV export crashed with a 500.

This awaits readData() in both handlers so they return the actual student data. Small, contained change to just those two routes.

readData() returns a MongoDB find().toArray() promise, but /students did
res.json(readData()) and /download did readData().map(...) with no await.
So /students serialized a pending promise as {} and /download crashed on
.map (a promise has no .map). Awaiting the promise returns the actual
student list from both routes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant