Last active
July 22, 2018 19:22
-
-
Save netgfx/ac203fbf28a2ccf4d6be0cc27c15041f to your computer and use it in GitHub Desktop.
Medium-snippet-BE-1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // The reference of the collection | |
| const bountyQueueRef = db.collection("bountyQueue"); | |
| exports.startMatchmaking = functions.https.onRequest((req, response) => { | |
| var data = req.query.data || req.params.data || req.body.data || ''; | |
| var userId = req.query.userId || req.params.userId || req.body.userId || 5000; | |
| let userFBId = data.userFBId; | |
| let tag = data.tag; | |
| var signature = data.signature || "123"; | |
| var isValid = validate(signature); | |
| if (isValid === true) { | |
| // data: {userFBId, userFirebaseId, tag, timestamp} | |
| data.flagged = false; | |
| bountyQueueRef.doc(userFBId).set(data, { merge: true }).then(docRef => { | |
| cors(req, response, () => {}); | |
| response.status(200).send(JSON.stringify({ "message": userFBId + " is on queue", "status": "success" })); | |
| }).catch(err => { | |
| console.log("An error occurred", err, err.message); | |
| cors(req, response, () => {}); | |
| response.status(500).send(JSON.stringify({ "message": "an error occurred" + err.message })); | |
| }); | |
| } else { | |
| console.log("An error occurred - invalid signature"); | |
| cors(req, response, () => {}); | |
| response.status(500).send(JSON.stringify({ "message": "invalid signature" })); | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment