Added panic handling

This commit is contained in:
Callum Gilchrist
2022-10-01 15:47:29 +01:00
parent 90d7af71be
commit d8512279a5

View File

@@ -5,11 +5,16 @@ const db = admin.firestore();
// // Create and Deploy Your First Cloud Functions // // Create and Deploy Your First Cloud Functions
// // https://firebase.google.com/docs/functions/write-firebase-functions // // https://firebase.google.com/docs/functions/write-firebase-functions
// //
exports.messageTester = functions.https.onRequest((request, response) => { exports.panic = functions.https.onRequest((request, response) => {
functions.logger.info("Message was requested", {structuredData: true}); functions.logger.info("Panic has been issued", {structuredData: true});
response.send("Sending message"); //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) => { exports.userCreated = functions.auth.user().onCreate((user) => {
return admin.auth().setCustomUserClaims(user.uid, { return admin.auth().setCustomUserClaims(user.uid, {
@@ -17,18 +22,18 @@ exports.userCreated = functions.auth.user().onCreate((user) => {
role: undefined, role: undefined,
}); });
}); });
// Redundant, I think
exports.roleDefined = functions.https.onCall((data, context) => { // exports.roleDefined = functions.https.onCall((data, context) => {
if (data.role == "firstAider") { // if (data.role == "firstAider") {
admin.auth().setCustomUserClaims(user.uid, { // admin.auth().setCustomUserClaims(user.uid, {
role: "firstAider", // role: "firstAider",
}); // });
} else { // } else {
return db.collection("users").doc(user.uid).set({ // return db.collection("users").doc(user.uid).set({
role: "patient", // role: "patient",
}); // });
} // }
}); // });
exports.firstAiderCreated = functions.firestore.document("first-aiders/{userId}/") exports.firstAiderCreated = functions.firestore.document("first-aiders/{userId}/")
.onCreate(async (snap, context) => { .onCreate(async (snap, context) => {
@@ -43,4 +48,4 @@ exports.firstAiderCreated = functions.firestore.document("patients/{userId}/")
role: "patient", role: "patient",
}); });
}); });
//patient firstAider //patient firstAider21