Skip to content

Commit

Permalink
Merge pull request #342 from concord-consortium/188732128-add-student…
Browse files Browse the repository at this point in the history
…-feedback-api-endpoint

feat: Added student feedback metadata api endpoint [PT-188732128]
  • Loading branch information
dougmartin authored Feb 4, 2025
2 parents 9fee192 + 88ad026 commit 9df3f46
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 1 deletion.
68 changes: 68 additions & 0 deletions functions/src/api/get-student-feedback-metadata.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { Request, Response } from "express"
import { getPath, getCollection } from "./helpers/paths"

interface FeedbackMetadata {
updatedAt: string;
}
type FeedbackMetadataMap = Record<string, FeedbackMetadata>;

const getFeedbackMetadata = (path: string, platformId: string, platformStudentId: string, map: FeedbackMetadataMap): Promise<FeedbackMetadataMap> => {
return getCollection(path)
.where("platformId", "==", platformId)
.where("platformStudentId", "==", platformStudentId)
.get()
.then((snapshot) => {
snapshot.docs.forEach((doc) => {
const data = doc.data();
const {resourceLinkId, updatedAt} = data;
if (resourceLinkId && updatedAt && updatedAt._seconds) {
map[resourceLinkId] = {updatedAt: updatedAt._seconds};
}
});
return map;
});
}

export default (req: Request, res: Response) => {
const {source, platform_id, platform_student_id} = req.query

if (!source) {
return res.error(500, "Missing source in query!")
}
if (typeof source !== "string") {
return res.error(500, "Malformed source")
}
if (!platform_id) {
return res.error(500, "Missing platform_id in query!")
}
if (typeof platform_id !== "string") {
return res.error(500, "Malformed platform_id")
}
if (!platform_student_id) {
return res.error(500, "Missing platform_student_id in query!")
}
if (typeof platform_student_id !== "string") {
return res.error(500, "Malformed platform_student_id")
}

return getPath(source, "activity_feedbacks")
.then((path) => {
return getFeedbackMetadata(path, platform_id, platform_student_id, {});
})
.then((feedbackMetadataMap) => {
return getPath(source, "question_feedbacks")
.then((path) => {
return {path, feedbackMetadataMap};
});
})
.then(({path, feedbackMetadataMap}) => {
return getFeedbackMetadata(path, platform_id, platform_student_id, feedbackMetadataMap);
})
.then((feedbackMetadataMap) => {
res.success({result: feedbackMetadataMap})
})
.catch((e) => {
console.error(e);
res.error(404, e.toString())
})
}
5 changes: 4 additions & 1 deletion functions/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import getResource from "./api/get-resource"
import fakeAnswer from "./api/fake-answer"
import getAnswer from "./api/get-answer"
import getPluginStates from "./api/get-plugin-states"
import getStudentFeedbackMetadata from "./api/get-student-feedback-metadata"

import {
createSyncDocAfterAnswerWritten,
Expand Down Expand Up @@ -40,7 +41,8 @@ api.get("/", (req, res) => {
"POST move_student_work": "Moves a students work from one class to another, requires a bearer token.",
"GET resource?source=<SOURCE>&url=<URL>": "Returns a resource under source with given url",
"GET answer?source=<SOURCE>&remote_endpoint=<REMOTE_ENDPOINT>&question_id=<QUESTION_ID>": "Returns the full answer document for a question by a learner",
"GET plugin_states?source=<SOURCE>&remote_endpoint=<REMOTE_ENDPOINT>": "Returns all the plugin states for a learner's resource"
"GET plugin_states?source=<SOURCE>&remote_endpoint=<REMOTE_ENDPOINT>": "Returns all the plugin states for a learner's resource",
"GET student_feedback_metadata?source=<SOURCE>&platform_id=<PLATFORM_ID>&platform_student_id=<PLATFORM_STUDENT_ID>": "Returns a map, keyed by offering id, of the student's activity and question feedback metadata",
}
})
})
Expand All @@ -50,6 +52,7 @@ api.post("/move_student_work", moveStudentWork)
api.get("/resource", getResource)
api.get("/answer", getAnswer)
api.get("/plugin_states", getPluginStates)
api.get("/student_feedback_metadata", getStudentFeedbackMetadata)
// TODO: comment out for final PR
api.get("/fakeAnswer", fakeAnswer)

Expand Down

0 comments on commit 9df3f46

Please sign in to comment.