From 3f59e2140ae783ece8ff50bc12ae67a950bc1ad5 Mon Sep 17 00:00:00 2001 From: Shams mosowi Date: Thu, 8 Oct 2020 13:34:54 +1100 Subject: [PATCH] triggerType util --- cloud_functions/functions/src/utils/index.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/cloud_functions/functions/src/utils/index.ts b/cloud_functions/functions/src/utils/index.ts index 099ed45e..ef8d2fb0 100644 --- a/cloud_functions/functions/src/utils/index.ts +++ b/cloud_functions/functions/src/utils/index.ts @@ -32,3 +32,10 @@ export async function asyncForEach(array: any[], callback: Function) { await callback(array[index], index, array); } } + +export const identifyTriggerType = (beforeData, afterData) => + Boolean(beforeData) && Boolean(afterData) + ? "update" + : Boolean(afterData) + ? "create" + : "delete";