Skip to content

Commit

Permalink
feat: timestamps for feedback (PT-188673526)
Browse files Browse the repository at this point in the history
  • Loading branch information
emcelroy committed Jan 15, 2025
1 parent 59dffdc commit b1470aa
Showing 1 changed file with 30 additions and 6 deletions.
36 changes: 30 additions & 6 deletions js/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -380,9 +380,21 @@ export function updateQuestionFeedbacks(data: any, reportState: IStateReportPart
// contextId is used by security rules.
feedback.contextId = contextId;
const path = reportQuestionFeedbacksFireStorePath(reportState.sourceKey, answerId);
return firebase.firestore()
.doc(path)
.set(feedback, {merge: true});
const docRef = firebase.firestore().doc(path);
return firebase.firestore().runTransaction(async (transaction) => {
const timestamp = firebase.firestore.FieldValue.serverTimestamp();
feedback.updatedAt = timestamp;
try {
const doc = await transaction.get(docRef);
if (!doc.exists) {
feedback.createdAt = timestamp;
}
} catch (error) {
console.warn("Document does not exist or read was denied.");
feedback.createdAt = timestamp;
}
transaction.set(docRef, feedback, { merge: true });
});
}

// The updateActivityFeedbacks API middleware calls out to the FireStore API.
Expand All @@ -401,9 +413,21 @@ export function updateActivityFeedbacks(data: any, reportState: IStateReportPart
feedback.platformStudentId = platformStudentId;
feedback.contextId = contextId;
const path = reportActivityFeedbacksFireStorePath(reportState.sourceKey, activityStudentKey);
return firebase.firestore()
.doc(path)
.set(feedback, {merge: true});
const docRef = firebase.firestore().doc(path);
return firebase.firestore().runTransaction(async (transaction) => {
const timestamp = firebase.firestore.FieldValue.serverTimestamp();
feedback.updatedAt = timestamp;
try {
const doc = await transaction.get(docRef);
if (!doc.exists) {
feedback.createdAt = timestamp;
}
} catch (error) {
console.warn("Document does not exist or read was denied.");
feedback.createdAt = timestamp;
}
transaction.set(docRef, feedback, { merge: true });
});
}

// The api-middleware calls this function when we need to load rubric in from a rubricUrl.
Expand Down

0 comments on commit b1470aa

Please sign in to comment.