Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: timestamps for feedback (PT-188673526) #489

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading