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
// // 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, {
@@ -17,18 +22,18 @@ exports.userCreated = functions.auth.user().onCreate((user) => {
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
//patient firstAider21