Skip to content

Instantly share code, notes, and snippets.

@netgfx
Last active July 22, 2018 19:22
Show Gist options
  • Select an option

  • Save netgfx/ac203fbf28a2ccf4d6be0cc27c15041f to your computer and use it in GitHub Desktop.

Select an option

Save netgfx/ac203fbf28a2ccf4d6be0cc27c15041f to your computer and use it in GitHub Desktop.
Medium-snippet-BE-1
// 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