From 72d099e05ec01772114216e4f6ce3a23b57c2340 Mon Sep 17 00:00:00 2001 From: Clayton Wilson Date: Tue, 3 Dec 2019 20:26:31 -0500 Subject: [PATCH] Fixing errors and warnings --- functions/handlers/post.js | 7 +++--- functions/handlers/users.js | 24 ++++++++++++++++--- twistter-frontend/src/Userline.js | 12 +++++----- twistter-frontend/src/Writing_Microblogs.js | 8 +++---- twistter-frontend/src/pages/Home.js | 8 +++---- twistter-frontend/src/pages/Login.js | 2 +- twistter-frontend/src/pages/verify.js | 2 +- .../src/redux/actions/userActions.js | 20 ++++++++++------ .../src/redux/reducers/userReducer.js | 9 ++++++- 9 files changed, 62 insertions(+), 30 deletions(-) diff --git a/functions/handlers/post.js b/functions/handlers/post.js index 440031a..292fa47 100644 --- a/functions/handlers/post.js +++ b/functions/handlers/post.js @@ -153,8 +153,8 @@ exports.quoteWithoutPost = (req, res) => { } }) .catch((err) => { - return res.status(500).json({error: 'Something is wrong'}); - + // return res.status(500).json({error: 'Something is wrong'}); + return res.status(500).json({error: err}); }) } @@ -195,7 +195,8 @@ exports.likePost = (req, res) => { } }) .catch((err) => { - return res.status(500).json({error: 'Something is wrong'}); + // return res.status(500).json({error: 'Something is wrong'}); + return res.status(500).json({error: err}); }) } diff --git a/functions/handlers/users.js b/functions/handlers/users.js index a4aea57..88fb87c 100644 --- a/functions/handlers/users.js +++ b/functions/handlers/users.js @@ -1,4 +1,5 @@ -/* eslint-disable promise/catch-or-return */ +/* eslint-disable promise/always-return */ + const { admin, db } = require("../util/admin"); const config = require("../util/config"); const { validateUpdateProfileInfo } = require("../util/validator"); @@ -304,12 +305,19 @@ exports.deleteUser = (req, res) => { }) .then(() => { resolve(); + return; }) .catch((err) => { console.log("error " + err); reject(err); + return; }) }) + .catch((err) => { + console.log(err); + return res.status(500).json({error: err}); + }) + }) } @@ -327,10 +335,12 @@ exports.deleteUser = (req, res) => { }) .then(() => { resolve(); + return; }) .catch((err) => { console.log(err); reject(err); + return; }) }) @@ -558,7 +568,11 @@ exports.addSubscription = (req, res) => { return res.status(500).json({ err }); }); return res.status(500).json({ error: "shouldn't execute" }); - }); + }) + .catch((err) => { + console.log(err); + return res.status(500).json({error: err}); + }) }; exports.getSubs = (req, res) => { @@ -598,5 +612,9 @@ exports.removeSub = (req, res) => { return res.status(500).json({ err }); }); return res.status(500).json({ error: "shouldn't execute" }); - }); + }) + .catch((err) => { + console.log(err); + return res.status(500).json({error: err}); + }) }; diff --git a/twistter-frontend/src/Userline.js b/twistter-frontend/src/Userline.js index 8c95620..6c61d6d 100644 --- a/twistter-frontend/src/Userline.js +++ b/twistter-frontend/src/Userline.js @@ -1,10 +1,10 @@ import React, { Component } from "react"; -import { BrowserRouter as Router } from 'react-router-dom'; -import Route from 'react-router-dom/Route'; +// import { BrowserRouter as Router } from 'react-router-dom'; +// import Route from 'react-router-dom/Route'; import axios from 'axios'; import Box from '@material-ui/core/Box' -import {borders} from '@material-ui/system'; -import { sizing } from '@material-ui/system'; +// import {borders} from '@material-ui/system'; +// import { sizing } from '@material-ui/system'; // var moment = require('moment'); @@ -41,7 +41,7 @@ class Userline extends Component {

Userline

- +

{sortedPosts.map((microBlog) =>

Microblog Title: {microBlog.microBlogTitle} @@ -50,7 +50,7 @@ class Userline extends Component {

Number of comments: {microBlog.commentCount}

Number of likes: {microBlog.likeCount}

Body of post: {microBlog.body} -

Tagged topics: {microBlog.microBlogTopics.join("," + " ")} +

Tagged topics: {microBlog.microBlogTopics.join(", ")}

)}

diff --git a/twistter-frontend/src/Writing_Microblogs.js b/twistter-frontend/src/Writing_Microblogs.js index 9cac7b7..e6f42a8 100644 --- a/twistter-frontend/src/Writing_Microblogs.js +++ b/twistter-frontend/src/Writing_Microblogs.js @@ -1,6 +1,6 @@ import React, { Component } from "react"; -import { BrowserRouter as Router } from "react-router-dom"; -import Route from "react-router-dom/Route"; +// import { BrowserRouter as Router } from "react-router-dom"; +// import Route from "react-router-dom/Route"; import axios from "axios"; class Writing_Microblogs extends Component { @@ -113,10 +113,10 @@ class Writing_Microblogs extends Component { rows={20} />
- Characters Left: {this.state.characterCount} +

Characters Left: {this.state.characterCount}

- +
diff --git a/twistter-frontend/src/pages/Home.js b/twistter-frontend/src/pages/Home.js index fd288c0..da382e9 100644 --- a/twistter-frontend/src/pages/Home.js +++ b/twistter-frontend/src/pages/Home.js @@ -28,7 +28,7 @@ class Home extends Component { axios .get("/getallPosts") .then(res => { - console.log(res.data); + // console.log(res.data); this.setState({ posts: res.data }) @@ -45,7 +45,7 @@ class Home extends Component { let postMarkup = this.state.posts ? ( this.state.posts.map(post => - + { @@ -53,7 +53,7 @@ class Home extends Component { () } - {post.userHandle} + {post.userHandle} {post.createdAt.substring(0,10) + " " + post.createdAt.substring(11,19)}
@@ -72,7 +72,7 @@ class Home extends Component { return ( authenticated ? - + diff --git a/twistter-frontend/src/pages/Login.js b/twistter-frontend/src/pages/Login.js index 336255a..43279fa 100644 --- a/twistter-frontend/src/pages/Login.js +++ b/twistter-frontend/src/pages/Login.js @@ -110,7 +110,7 @@ export class Login extends Component { logo

- + Log in to Twistter

diff --git a/twistter-frontend/src/pages/verify.js b/twistter-frontend/src/pages/verify.js index e36a317..88a804e 100644 --- a/twistter-frontend/src/pages/verify.js +++ b/twistter-frontend/src/pages/verify.js @@ -89,7 +89,7 @@ export class verify extends Component { render() { const { classes } = this.props; - const { errors, loading } = this.state; + const { loading } = this.state; return ( diff --git a/twistter-frontend/src/redux/actions/userActions.js b/twistter-frontend/src/redux/actions/userActions.js index 5993804..eae7a00 100644 --- a/twistter-frontend/src/redux/actions/userActions.js +++ b/twistter-frontend/src/redux/actions/userActions.js @@ -1,6 +1,18 @@ -import {SET_USER, SET_ERRORS, CLEAR_ERRORS, LOADING_UI, SET_AUTHENTICATED, SET_UNAUTHENTICATED} from '../types'; +import { + SET_USER, + SET_ERRORS, + CLEAR_ERRORS, + LOADING_UI, + // SET_AUTHENTICATED, + SET_UNAUTHENTICATED +} from '../types'; import axios from 'axios'; +const setAuthorizationHeader = (token) => { + const FBIdToken = `Bearer ${token}`; + localStorage.setItem('FBIdToken', FBIdToken); + axios.defaults.headers.common['Authorization'] = FBIdToken; +} export const getUserData = () => (dispatch) => { axios.get('/user') @@ -80,9 +92,3 @@ export const deleteUser = () => (dispatch) => { delete axios.defaults.headers.common['Authorization']; dispatch({ type: SET_UNAUTHENTICATED }); } - -const setAuthorizationHeader = (token) => { - const FBIdToken = `Bearer ${token}`; - localStorage.setItem('FBIdToken', FBIdToken); - axios.defaults.headers.common['Authorization'] = FBIdToken; -} \ No newline at end of file diff --git a/twistter-frontend/src/redux/reducers/userReducer.js b/twistter-frontend/src/redux/reducers/userReducer.js index 7a29e90..e26509a 100644 --- a/twistter-frontend/src/redux/reducers/userReducer.js +++ b/twistter-frontend/src/redux/reducers/userReducer.js @@ -1,4 +1,11 @@ -import {SET_USER, SET_ERRORS, CLEAR_ERRORS, LOADING_UI, SET_AUTHENTICATED, SET_UNAUTHENTICATED} from '../types'; +import { + SET_USER, + // SET_ERRORS, + // CLEAR_ERRORS, + // LOADING_UI, + SET_AUTHENTICATED, + SET_UNAUTHENTICATED +} from '../types'; const initialState = { authenticated: false,