From 40e91caf4704f93a6f55255ab5c3fe6c88996059 Mon Sep 17 00:00:00 2001 From: AYM1607 Date: Sat, 13 Apr 2019 21:26:19 -0500 Subject: [PATCH] Added docs for the [pendingTasksUpdater] firebase function --- functions/src/pending_tasks_updater.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/functions/src/pending_tasks_updater.ts b/functions/src/pending_tasks_updater.ts index 9e9e25e..c253d81 100644 --- a/functions/src/pending_tasks_updater.ts +++ b/functions/src/pending_tasks_updater.ts @@ -67,14 +67,32 @@ const incrementPendingTasks = async ( export const pendingTasksUpdater: functions.CloudFunction> = functions.firestore .document('tasks/{taskId}') .onWrite(async (change, _) => { + /// Snapshot of the document before the operation. + /// + /// Only applicable for update and delete operations. const before: DocumentSnapshot = change.before; + + /// Snapshot of the document after the operation. + /// + /// Only applicable for update and create operations. const after: DocumentSnapshot = change.after; + + /// Operation performed to the task. let action: string; + + /// Reference to the user dociment linked to this task. let userDocument: DocumentReference; + + /// Reference to the event document linked to this task before the operation. let eventDocument: DocumentReference; + + /// Reference to the event document linked to this task after the operation. let eventDocumentBefore: DocumentReference | null; + if (change.after.exists && change.before.exists) { + /// Exit the funciton if case this is an update operation and the + /// event and priority of the taks haven't changed. if (before.get('priority') === after.get('priority') || before.get('event') === after.get('event')) { console.log('Nothing to update, exiting function'); return true;