I am working on a personal web application project. I have an arrow function that is being triggered every time user updates document inside movieIndex collection. Whenever my app launches it updates isBeingReviewed field of a movie document from False to True. I want to create a cloud function which sets the value of isBeingReviewed to false after 15 minutes. How can I access the updated value and set field to false? Is timeout a correct approach?
admin.initializeApp();
exports.newMessage = functions.firestore
.document("movieIndex/{movie}")
.onUpdate(async (change, context) => {
const changedDoc = change.after.data();
if (changedDoc.isBeingReviewed == true)
{
console.log("The current status of isBeingReviewed is equal to TRUE, set it to false after 15 minutes ")
setTimeout( access changed value and set it to false ,1000 * 60 * 15)
}
else
{
console.log("The current status of isBeingReviewed is equal to FALSE")
}
});