-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #342 from concord-consortium/188732128-add-student…
…-feedback-api-endpoint feat: Added student feedback metadata api endpoint [PT-188732128]
- Loading branch information
Showing
2 changed files
with
72 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters