From d8512279a50db0e07a0a2385127c29b90c5e814f Mon Sep 17 00:00:00 2001 From: Callum Gilchrist <43007634+CallumGilly@users.noreply.github.com> Date: Sat, 1 Oct 2022 15:47:29 +0100 Subject: [PATCH] Added panic handling --- functions/index.js | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/functions/index.js b/functions/index.js index c4bdfe6..eb2a1cd 100644 --- a/functions/index.js +++ b/functions/index.js @@ -5,30 +5,35 @@ const db = admin.firestore(); // // Create and Deploy Your First Cloud Functions // // https://firebase.google.com/docs/functions/write-firebase-functions // -exports.messageTester = functions.https.onRequest((request, response) => { - functions.logger.info("Message was requested", {structuredData: true}); - response.send("Sending message"); +exports.panic = functions.https.onRequest((request, response) => { + functions.logger.info("Panic has been issued", {structuredData: true}); + //Code to make a panic goes here + db.collection("panic-events").add({ + patient: request.body.patient, + resolved: false, + timestamp: new Date(), + }); + response.send(`patient: ${request.body.patient}`); }); - exports.userCreated = functions.auth.user().onCreate((user) => { return admin.auth().setCustomUserClaims(user.uid, { admin: false, role: undefined, }); }); - -exports.roleDefined = functions.https.onCall((data, context) => { - if (data.role == "firstAider") { - admin.auth().setCustomUserClaims(user.uid, { - role: "firstAider", - }); - } else { - return db.collection("users").doc(user.uid).set({ - role: "patient", - }); - } -}); +// Redundant, I think +// exports.roleDefined = functions.https.onCall((data, context) => { +// if (data.role == "firstAider") { +// admin.auth().setCustomUserClaims(user.uid, { +// role: "firstAider", +// }); +// } else { +// return db.collection("users").doc(user.uid).set({ +// role: "patient", +// }); +// } +// }); exports.firstAiderCreated = functions.firestore.document("first-aiders/{userId}/") .onCreate(async (snap, context) => { @@ -43,4 +48,4 @@ exports.firstAiderCreated = functions.firestore.document("patients/{userId}/") role: "patient", }); }); -//patient firstAider \ No newline at end of file +//patient firstAider21 \ No newline at end of file