From 90442fe3cd885b5b7e48fc2ba699f3c4642ab3b3 Mon Sep 17 00:00:00 2001 From: Clayton Wilson Date: Sun, 29 Sep 2019 23:59:36 -0400 Subject: [PATCH] Fixing 'firebase deploy' errors and warnings --- functions/handlers/post.js | 4 ++-- functions/handlers/users.js | 6 +++++- functions/util/validator.js | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/functions/handlers/post.js b/functions/handlers/post.js index 71b97eb..e2d195b 100644 --- a/functions/handlers/post.js +++ b/functions/handlers/post.js @@ -17,11 +17,11 @@ exports.putPost = (req, res) => { .then((doc) => { const resPost = newPost; resPost.postId = doc.id; - res.json(resPost); + return res.status(200).json(resPost); }) .catch((err) => { - res.status(500).json({ error: 'something is wrong'}); console.error(err); + return res.status(500).json({ error: 'something is wrong'}); }); }; diff --git a/functions/handlers/users.js b/functions/handlers/users.js index 240bfdd..c165ae0 100644 --- a/functions/handlers/users.js +++ b/functions/handlers/users.js @@ -9,6 +9,10 @@ exports.getProfileInfo = (req, res) => { db.collection('users').doc(req.user.handle).get() .then((data) => { return res.status(200).json(data.data()); + }) + .catch((err) => { + console.error(err); + return res.status(500).json(err); }); }; @@ -41,7 +45,7 @@ exports.updateProfileInfo = (req, res) => { exports.getUserDetails = (req, res) => { let userData = {}; - db.doc('/users/${req.params.handle}').get().then((doc) => { + db.doc(`/users/${req.params.handle}`).get().then((doc) => { if (doc.exists) { userData.user = doc.data(); return db.collection('post').where('userHandle', '==', req.params.handle) diff --git a/functions/util/validator.js b/functions/util/validator.js index ca29c6c..3ab6226 100644 --- a/functions/util/validator.js +++ b/functions/util/validator.js @@ -4,7 +4,7 @@ const isEmpty = (str) => { }; const isEmail = (str) => { - const emailRegEx = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; + const emailRegEx = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; if (str.match(emailRegEx)) return true; else return false; }