From ee8e11ff9bb717a1e23b1e55c3d3e689fff2d53c Mon Sep 17 00:00:00 2001 From: Pritimay Sarkar Date: Wed, 27 Sep 2023 09:37:56 +0530 Subject: [PATCH] add retestMarking function --- cloud-functions/nodejs/functions/index.js | 30 ++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/cloud-functions/nodejs/functions/index.js b/cloud-functions/nodejs/functions/index.js index 6653430..6f058a2 100644 --- a/cloud-functions/nodejs/functions/index.js +++ b/cloud-functions/nodejs/functions/index.js @@ -247,4 +247,32 @@ exports.migrateUsers = async (event, context) => { } }) } -}; \ No newline at end of file +}; + + +/** + * Triggered by a change to a Firestore document. + * + * @param {!Object} event Event payload. + * @param {!Object} context Metadata for the event. + */ + +const admin = require("firebase-admin"); + +admin.initializeApp(); + +exports.retestMarking = async (event, context) => { + const resource = context.resource; + // log out the resource string that triggered the function + console.log('Function triggered by change to: ' + resource); + // now log the full event object + console.log(JSON.stringify(event)); + const { _id, classificationResult } = event.value.fields; + console.log("classificationResult", classificationResult.stringValue); + if (classificationResult?.stringValue?.includes("Negative Borderline")) { + await admin.firestore().collection("patientData").where("_id", "==", _id.stringValue).update({ + testStatus: false, + incubationTime: admin.firestore.FieldValue.delete() + }); + } +};