diff --git a/application/Dockerfile b/application/Dockerfile
index a3c01a52..6f724533 100644
--- a/application/Dockerfile
+++ b/application/Dockerfile
@@ -1,4 +1,4 @@
-FROM node:11
+FROM node:latest
WORKDIR /home/node/application
diff --git a/application/package.json b/application/package.json
index a148c9a0..0f9313c0 100644
--- a/application/package.json
+++ b/application/package.json
@@ -3,14 +3,14 @@
"version": "0.1.0",
"private": true,
"dependencies": {
- "axios": "^0.19.0",
- "bootstrap": "^4.3.1",
- "react": "^16.8.6",
- "react-dom": "^16.8.6",
- "react-redux": "^7.1.0",
- "react-router-dom": "^5.0.1",
- "react-scripts": "3.0.1",
- "redux": "^4.0.1",
+ "axios": "^0.21.1",
+ "bootstrap": "^5.0.1",
+ "react": "^17.0.2",
+ "react-dom": "^17.0.2",
+ "react-redux": "^7.2.4",
+ "react-router-dom": "^5.2.0",
+ "react-scripts": "4.0.3",
+ "redux": "^4.1.0",
"redux-thunk": "^2.3.0"
},
"scripts": {
diff --git a/application/public/index.html b/application/public/index.html
index dd1ccfd4..db887f8d 100644
--- a/application/public/index.html
+++ b/application/public/index.html
@@ -1,38 +1,27 @@
-
-
-
-
-
-
-
-
- React App
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+ React App
+
+
+
+
+
+
diff --git a/application/public/manifest.json b/application/public/manifest.json
index 1f2f141f..952449d9 100644
--- a/application/public/manifest.json
+++ b/application/public/manifest.json
@@ -1,15 +1,15 @@
{
- "short_name": "React App",
- "name": "Create React App Sample",
- "icons": [
- {
- "src": "favicon.ico",
- "sizes": "64x64 32x32 24x24 16x16",
- "type": "image/x-icon"
- }
- ],
- "start_url": ".",
- "display": "standalone",
- "theme_color": "#000000",
- "background_color": "#ffffff"
+ "short_name": "React App",
+ "name": "Create React App Sample",
+ "icons": [
+ {
+ "src": "favicon.ico",
+ "sizes": "64x64 32x32 24x24 16x16",
+ "type": "image/x-icon"
+ }
+ ],
+ "start_url": ".",
+ "display": "standalone",
+ "theme_color": "#000000",
+ "background_color": "#ffffff"
}
diff --git a/application/src/App.js b/application/src/App.js
index dff74375..c07555e4 100644
--- a/application/src/App.js
+++ b/application/src/App.js
@@ -1,17 +1,17 @@
-import React, { Component } from 'react';
-import { Provider } from 'react-redux';
-import AppRouter from './router/appRouter';
-import store from './redux/store';
-import './App.css';
+import React, { Component } from 'react';
+import { Provider } from 'react-redux';
+import AppRouter from './router/appRouter';
+import store from './redux/store';
+import './App.css';
class App extends Component {
- render() {
- return (
-
-
-
- )
- }
+ render() {
+ return (
+
+
+
+ )
+ }
}
export default App;
diff --git a/application/src/App.test.js b/application/src/App.test.js
index a754b201..ad442dd2 100644
--- a/application/src/App.test.js
+++ b/application/src/App.test.js
@@ -1,9 +1,9 @@
-import React from 'react';
-import ReactDOM from 'react-dom';
-import App from './App';
+import React from 'react';
+import ReactDOM from 'react-dom';
+import App from './App';
it('renders without crashing', () => {
- const div = document.createElement('div');
- ReactDOM.render(, div);
- ReactDOM.unmountComponentAtNode(div);
+ const div = document.createElement('div');
+ ReactDOM.render(, div);
+ ReactDOM.unmountComponentAtNode(div);
});
diff --git a/application/src/components/common/template.css b/application/src/components/common/template.css
index fe0b4b90..49970fe9 100644
--- a/application/src/components/common/template.css
+++ b/application/src/components/common/template.css
@@ -1,24 +1,24 @@
.bg-layer {
- background: #7A5114;
- min-height: 100vh;
- width: 100%;
+ background: #7A5114;
+ min-height: 100vh;
+ width: 100%;
}
.fg-layer {
- background: #ECEAEA;
- min-height: 100vh;
- margin-left: 20%;
- margin-right: 20%;
+ background: #ECEAEA;
+ min-height: 100vh;
+ margin-left: 20%;
+ margin-right: 20%;
}
.logo {
- display: block;
- font-family: "Optima";
- font-size: 4em;
- padding-left: 20%;
- padding-right: 20%;
- padding-top: 5%;
- text-align: center;
- text-decoration: underline;
- text-decoration-color: #A43F3F;
+ display: block;
+ font-family: "Optima";
+ font-size: 4em;
+ padding-left: 20%;
+ padding-right: 20%;
+ padding-top: 5%;
+ text-align: center;
+ text-decoration: underline;
+ text-decoration-color: #A43F3F;
}
\ No newline at end of file
diff --git a/application/src/components/common/template.js b/application/src/components/common/template.js
index 02d6e6ed..030d5687 100644
--- a/application/src/components/common/template.js
+++ b/application/src/components/common/template.js
@@ -1,17 +1,18 @@
-import React from 'react';
-import { Nav } from '../../components';
-import './template.css';
+import React from 'react';
+import { Nav } from '../../components';
+import './template.css';
const Template = props => {
- return (
-
-
-
-
- {props.children}
-
-
- );
+ return (
+
+
+
+ {/* display nav component */}
+
+ { props.children }
+
+
+ );
}
export default Template;
\ No newline at end of file
diff --git a/application/src/components/dashboard/dashboard.js b/application/src/components/dashboard/dashboard.js
index f1cd44bc..9c1f2477 100644
--- a/application/src/components/dashboard/dashboard.js
+++ b/application/src/components/dashboard/dashboard.js
@@ -1,21 +1,20 @@
import React, { Component } from 'react';
-import { connect } from 'react-redux';
-import { Link } from 'react-router-dom';
-import './Dasboard.css';
+import { connect } from 'react-redux';
+import './Dasboard.css';
const mapStateToProps = state => ({
- temp: state.temp
+ temp: state.temp
});
class Dashboard extends Component {
- render() {
- console.log('props', this.props);
- return (
-
-
Dashboard
-
- )
- }
+ render() {
+ console.log('props from the dashboard', this.props);
+ return (
+
+
Dashboard
+
+ )
+ }
}
export default connect(mapStateToProps, null)(Dashboard);
diff --git a/application/src/components/index.js b/application/src/components/index.js
index 67b0fece..8d70b610 100644
--- a/application/src/components/index.js
+++ b/application/src/components/index.js
@@ -1,8 +1,8 @@
-import Login from './login/login';
-import Main from './main/main';
-import Nav from './nav/nav';
-import OrderForm from './order-form/orderForm';
-import Template from './common/template';
-import ViewOrders from './view-orders/viewOrders';
+import Login from './login/login';
+import Main from './main/main';
+import Nav from './nav/nav';
+import OrderForm from './order-form/orderForm';
+import Template from './common/template';
+import ViewOrders from './view-orders/viewOrders';
export { Login, OrderForm, Main, Nav, Template, ViewOrders };
diff --git a/application/src/components/login/login-form/loginForm.js b/application/src/components/login/login-form/loginForm.js
index 73aba471..e99cc9af 100644
--- a/application/src/components/login/login-form/loginForm.js
+++ b/application/src/components/login/login-form/loginForm.js
@@ -1,46 +1,56 @@
-import React, { Component } from 'react';
-import { connect } from 'react-redux';
-import { loginUser } from '../../../redux/actions/authActions'
+import React, { Component } from 'react';
+import { connect } from 'react-redux';
+import { loginUser } from '../../../redux/actions/authActions'
const mapActionsToProps = dispatch => ({
- commenceLogin(email, password) {
- dispatch(loginUser(email, password))
- }
+ commenceLogin(email, password) {
+ dispatch(loginUser(email, password))
+ }
})
class LoginForm extends Component {
- state = {
- email: "",
- password: "",
- }
+ state = {
+ email: "",
+ password: "",
+ }
- login(e) {
- e.preventDefault();
- this.props.commenceLogin(this.state.email, this.state.password);
- this.props.onLogin();
- }
+ login(e) {
+ e.preventDefault();
+ this.props.commenceLogin(this.state.email, this.state.password);
+ this.props.onLogin();
+ }
- onChange(key, val) {
- this.setState({ [key]: val });
- }
+ onChange(key, val) {
+ this.setState({ [key]: val });
+ }
- render() {
- return (
-
- );
- }
+ render() {
+ return (
+ // need form validation form email and password to let user know if they typed in a correct email or if there account exist in the database
+
+ );
+ }
}
export default connect(null, mapActionsToProps)(LoginForm);
\ No newline at end of file
diff --git a/application/src/components/login/login.js b/application/src/components/login/login.js
index 0172c5b6..063ff1f4 100644
--- a/application/src/components/login/login.js
+++ b/application/src/components/login/login.js
@@ -1,19 +1,18 @@
-import React, { Component } from 'react';
-import LoginForm from './login-form/loginForm';
-import './login.css';
+import React, { Component } from 'react';
+import LoginForm from './login-form/loginForm';
+import './login.css';
class Login extends Component {
-
- render() {
- return (
-
-
Login Screen
-
- {this.props.history.push('/view-orders')}}/>
-
-
- )
- }
+ render() {
+ return (
+
+
Login Screen
+
+ {this.props.history.push('/view-orders')}}/>
+
+
+ )
+ }
}
export default Login;
\ No newline at end of file
diff --git a/application/src/components/main/main.js b/application/src/components/main/main.js
index cadae1cd..f004d720 100644
--- a/application/src/components/main/main.js
+++ b/application/src/components/main/main.js
@@ -1,25 +1,25 @@
-import React, { Component } from 'react';
-import { connect } from 'react-redux';
-import { Link } from 'react-router-dom';
-import './main.css';
+import React, { Component } from 'react';
+import { connect } from 'react-redux';
+import { Link } from 'react-router-dom';
+import './main.css';
const mapStateToProps = state => ({
- temp: state.temp
+ temp: state.temp
});
class Main extends Component {
- render() {
- console.log('props', this.props);
- return (
-
-
Bruce's Diner Ordering Application
- Please login to continue
-
-
-
-
- )
- }
+ render() {
+ console.log('props from main.js', this.props);
+ return (
+
+
Bruce's Diner Ordering Application
+ Please login to continue
+
+
+
+
+ )
+ }
}
export default connect(mapStateToProps, null)(Main);
diff --git a/application/src/components/nav/nav.js b/application/src/components/nav/nav.js
index 51c5992d..fd73e50e 100644
--- a/application/src/components/nav/nav.js
+++ b/application/src/components/nav/nav.js
@@ -1,16 +1,19 @@
-import React from "react";
-import { Link } from "react-router-dom";
-import "./nav.css";
+import React from "react";
+import { Link } from "react-router-dom";
+import "./nav.css";
const Nav = (props) => {
return (
-
+
-
+
diff --git a/application/src/components/order-form/orderForm.js b/application/src/components/order-form/orderForm.js
index 29258203..4694b7ee 100644
--- a/application/src/components/order-form/orderForm.js
+++ b/application/src/components/order-form/orderForm.js
@@ -1,10 +1,10 @@
-import React, { Component } from 'react';
-import { Template } from '../../components';
-import { connect } from 'react-redux';
-import { SERVER_IP } from '../../private';
-import './orderForm.css';
+import React, { Component } from 'react';
+import { Template } from '../../components';
+import { connect } from 'react-redux';
+import { SERVER_IP } from '../../private';
+import './orderForm.css';
-const ADD_ORDER_URL = `${SERVER_IP}/api/add-order`
+const ADD_ORDER_URL = `${SERVER_IP}/api/add-order`;
const mapStateToProps = (state) => ({
auth: state.auth,
@@ -19,31 +19,35 @@ class OrderForm extends Component {
}
}
+ // set the item the user selected in the menu and property should be order_item not item
menuItemChosen(event) {
- this.setState({ item: event.target.value });
+ this.setState({ order_item: event.target.value });
}
+ // set the quantity the user selected in the menu
menuQuantityChosen(event) {
this.setState({ quantity: event.target.value });
}
+ // when the user clicks on submit button this function will post there order
submitOrder(event) {
event.preventDefault();
- if (this.state.order_item === "") return;
- fetch(ADD_ORDER_URL, {
- method: 'POST',
- body: JSON.stringify({
- order_item: this.state.order_item,
- quantity: this.state.quantity,
- ordered_by: this.props.auth.email || 'Unknown!',
- }),
- headers: {
- 'Content-Type': 'application/json'
- }
- })
- .then(res => res.json())
- .then(response => console.log("Success", JSON.stringify(response)))
- .catch(error => console.error(error));
+ console.log(this.state.order_item);
+ if (this.state.order_item === "") return;
+ fetch(ADD_ORDER_URL, {
+ method: 'POST',
+ body: JSON.stringify({
+ order_item: this.state.order_item,
+ quantity: this.state.quantity,
+ ordered_by: this.props.auth.email || 'Unknown!'
+ }),
+ headers: {
+ 'Content-Type': 'application/json'
+ }
+ })
+ .then(res => res.json())
+ .then(response => console.log("Success", JSON.stringify(response)))
+ .catch(error => console.error(error));
}
render() {
@@ -51,19 +55,20 @@ class OrderForm extends Component {
diff --git a/application/src/components/view-orders/viewOrders.js b/application/src/components/view-orders/viewOrders.js
index 86e67113..f61756d6 100644
--- a/application/src/components/view-orders/viewOrders.js
+++ b/application/src/components/view-orders/viewOrders.js
@@ -1,13 +1,14 @@
-import React, { Component } from 'react';
-import { Template } from '../../components';
-import { SERVER_IP } from '../../private';
-import './viewOrders.css';
+import React, { Component } from 'react';
+import { Template } from '../../components';
+import { SERVER_IP } from '../../private';
+import './viewOrders.css';
class ViewOrders extends Component {
state = {
orders: []
}
+ //
componentDidMount() {
fetch(`${SERVER_IP}/api/current-orders`)
.then(response => response.json())
@@ -24,7 +25,7 @@ class ViewOrders extends Component {
return (
- {this.state.orders.map(order => {
+ { this.state.orders.map(order => {
const createdDate = new Date(order.createdAt);
return (
@@ -35,11 +36,11 @@ class ViewOrders extends Component {
Order placed at {`${createdDate.getHours()}:${createdDate.getMinutes()}:${createdDate.getSeconds()}`}
Quantity: {order.quantity}
-
-
-
-
-
+
+
+
+
+
);
})}
diff --git a/application/src/index.css b/application/src/index.css
index 4a1df4db..a118cbe3 100644
--- a/application/src/index.css
+++ b/application/src/index.css
@@ -1,13 +1,10 @@
body {
- margin: 0;
- font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen",
- "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue",
- sans-serif;
- -webkit-font-smoothing: antialiased;
- -moz-osx-font-smoothing: grayscale;
+ margin: 0;
+ font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif;
+ -webkit-font-smoothing: antialiased;
+ -moz-osx-font-smoothing: grayscale;
}
code {
- font-family: source-code-pro, Menlo, Monaco, Consolas, "Courier New",
- monospace;
+ font-family: source-code-pro, Menlo, Monaco, Consolas, "Courier New", monospace;
}
diff --git a/application/src/index.js b/application/src/index.js
index ec986d0c..0e3006ed 100644
--- a/application/src/index.js
+++ b/application/src/index.js
@@ -1,9 +1,9 @@
-import React from 'react';
-import ReactDOM from 'react-dom';
-import './index.css';
-import App from './App';
-import * as serviceWorker from './serviceWorker';
-import 'bootstrap/dist/css/bootstrap.min.css';
+import React from 'react';
+import ReactDOM from 'react-dom';
+import './index.css';
+import App from './App';
+import * as serviceWorker from './serviceWorker';
+import 'bootstrap/dist/css/bootstrap.min.css';
ReactDOM.render(, document.getElementById('root'));
diff --git a/application/src/oldApp.css b/application/src/oldApp.css
index b41d297c..cf280ea8 100644
--- a/application/src/oldApp.css
+++ b/application/src/oldApp.css
@@ -1,33 +1,33 @@
.App {
- text-align: center;
+ text-align: center;
}
.App-logo {
- animation: App-logo-spin infinite 20s linear;
- height: 40vmin;
- pointer-events: none;
+ animation: App-logo-spin infinite 20s linear;
+ height: 40vmin;
+ pointer-events: none;
}
.App-header {
- background-color: #282c34;
- min-height: 100vh;
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- font-size: calc(10px + 2vmin);
- color: white;
+ background-color: #282c34;
+ min-height: 100vh;
+ display: flex;
+ flex-direction: column;
+ align-items: center;
+ justify-content: center;
+ font-size: calc(10px + 2vmin);
+ color: white;
}
.App-link {
- color: #61dafb;
+ color: #61dafb;
}
@keyframes App-logo-spin {
- from {
- transform: rotate(0deg);
- }
- to {
- transform: rotate(360deg);
- }
+ from {
+ transform: rotate(0deg);
+ }
+ to {
+ transform: rotate(360deg);
+ }
}
diff --git a/application/src/oldApp.js b/application/src/oldApp.js
index ce9cbd29..d0ab5f57 100644
--- a/application/src/oldApp.js
+++ b/application/src/oldApp.js
@@ -1,26 +1,22 @@
-import React from 'react';
-import logo from './logo.svg';
-import './App.css';
+import React from 'react';
+import logo from './logo.svg';
+import './App.css';
function App() {
- return (
-
- );
+ return (
+
+ );
}
export default App;
diff --git a/application/src/private.js b/application/src/private.js
index 55c0e0e1..696afa1a 100644
--- a/application/src/private.js
+++ b/application/src/private.js
@@ -1,3 +1,3 @@
const windowsPlatforms = ['Win32', 'Win64', 'Windows', 'WinCE'];
-export const SERVER_IP = windowsPlatforms.indexOf(window.navigator.platform) < 0 ? 'http://localhost:4000' : 'http://192.168.99.100:4000';
\ No newline at end of file
+export const SERVER_IP = windowsPlatforms.indexOf(window.navigator.platform) < 0 ? 'http://localhost:4000' : 'http://192.168.50.208:4000';
\ No newline at end of file
diff --git a/application/src/redux/actions/authActions.js b/application/src/redux/actions/authActions.js
index 5c152a4b..6625c38f 100644
--- a/application/src/redux/actions/authActions.js
+++ b/application/src/redux/actions/authActions.js
@@ -1,16 +1,16 @@
-import { LOGIN, LOGOUT } from './types';
-import { SERVER_IP } from '../../private'
+import { LOGIN, LOGOUT } from './types';
+import { SERVER_IP } from '../../private'
const finishLogin = (email, token) => {
return {
type: LOGIN,
payload: {
email,
- token,
+ token
}
}
}
-
+// log the user in using there email and password
export const loginUser = (email, password) => {
return (dispatch) => {
fetch(`${SERVER_IP}/api/login`, {
@@ -22,7 +22,8 @@ export const loginUser = (email, password) => {
headers: {
'Content-Type': 'application/json'
},
- }).then(response => response.json())
+ })
+ .then(response => response.json())
.then(response => {
if (response.success) {
dispatch(finishLogin(response.email, response.token));
@@ -31,6 +32,7 @@ export const loginUser = (email, password) => {
};
}
+// logthe user out
export const logoutUser = () => {
return {
type: LOGOUT,
diff --git a/application/src/redux/reducers/authReducer.js b/application/src/redux/reducers/authReducer.js
index 4f3da462..b62f3310 100644
--- a/application/src/redux/reducers/authReducer.js
+++ b/application/src/redux/reducers/authReducer.js
@@ -1,8 +1,9 @@
-import { LOGIN, LOGOUT } from '../actions/types'
+import { LOGIN, LOGOUT } from '../actions/types';
-const INITIAL_STATE = { email: null, token: null };
+const INITIAL_STATE = { email: null, token: null };
-export default (state = INITIAL_STATE, action) => {
+// getting error "Assign arrow function to a variable before exporting as module default import/no-anonymous-default-export" and needed to declare const first before it can export
+ const authReducer = (state = INITIAL_STATE, action) => {
switch (action.type) {
case LOGIN:
return { ...state, email: action.payload.login, token: action.payload.token }
@@ -11,4 +12,6 @@ export default (state = INITIAL_STATE, action) => {
default:
return state;
}
-}
\ No newline at end of file
+}
+
+export default authReducer;
\ No newline at end of file
diff --git a/application/src/redux/reducers/index.js b/application/src/redux/reducers/index.js
index f83a4363..cf8ec0cb 100644
--- a/application/src/redux/reducers/index.js
+++ b/application/src/redux/reducers/index.js
@@ -1,8 +1,8 @@
-import { combineReducers } from 'redux';
-import TempReducer from './tempReducer';
-import authReducer from './authReducer';
+import { combineReducers } from 'redux';
+import TempReducer from './tempReducer';
+import authReducer from './authReducer';
export default combineReducers({
- temp: TempReducer,
- auth: authReducer,
+ temp: TempReducer,
+ auth: authReducer
});
\ No newline at end of file
diff --git a/application/src/redux/reducers/tempReducer.js b/application/src/redux/reducers/tempReducer.js
index c99d0d76..d46f4324 100644
--- a/application/src/redux/reducers/tempReducer.js
+++ b/application/src/redux/reducers/tempReducer.js
@@ -1,9 +1,11 @@
-const INITIAL_STATE = { test: '' };
-
-export default (state = INITIAL_STATE, action) => {
- switch (action.type) {
- default:
- return state;
- }
+const INITIAL_STATE = { test: '' };
+// getting error "Assign arrow function to a variable before exporting as module default import/no-anonymous-default-export" and needed to declare const first before it can export
+const tempReducer = (state = INITIAL_STATE, action) => {
+ switch (action.type) {
+ default:
+ return state;
+ }
}
+
+export default tempReducer;
\ No newline at end of file
diff --git a/application/src/redux/store.js b/application/src/redux/store.js
index efb7a5a3..d72edac5 100644
--- a/application/src/redux/store.js
+++ b/application/src/redux/store.js
@@ -1,6 +1,6 @@
-import { createStore, applyMiddleware } from 'redux';
-import ReduxThunk from 'redux-thunk';
-import reducers from './reducers';
+import { createStore, applyMiddleware } from 'redux';
+import ReduxThunk from 'redux-thunk';
+import reducers from './reducers';
const store = createStore(reducers, {}, applyMiddleware(ReduxThunk));
diff --git a/application/src/router/appRouter.js b/application/src/router/appRouter.js
index 23bbe273..cea43ad5 100644
--- a/application/src/router/appRouter.js
+++ b/application/src/router/appRouter.js
@@ -1,16 +1,16 @@
-import React from 'react';
-import { BrowserRouter as Router, Route } from 'react-router-dom';
-import { Main, Login, OrderForm, ViewOrders } from '../components';
+import React from 'react';
+import { BrowserRouter as Router, Route } from 'react-router-dom';
+import { Main, Login, OrderForm, ViewOrders } from '../components';
const AppRouter = (props) => {
- return (
-
-
-
-
-
-
- );
+ return (
+
+
+
+
+
+
+ );
}
export default AppRouter;
diff --git a/application/src/serviceWorker.js b/application/src/serviceWorker.js
index f8c7e50c..33687e10 100644
--- a/application/src/serviceWorker.js
+++ b/application/src/serviceWorker.js
@@ -11,125 +11,111 @@
// opt-in, read https://bit.ly/CRA-PWA
const isLocalhost = Boolean(
- window.location.hostname === 'localhost' ||
+ window.location.hostname === 'localhost' ||
// [::1] is the IPv6 localhost address.
window.location.hostname === '[::1]' ||
// 127.0.0.1/8 is considered localhost for IPv4.
- window.location.hostname.match(
- /^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/
- )
+ window.location.hostname.match(/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/)
);
export function register(config) {
- if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) {
- // The URL constructor is available in all browsers that support SW.
- const publicUrl = new URL(process.env.PUBLIC_URL, window.location.href);
- if (publicUrl.origin !== window.location.origin) {
- // Our service worker won't work if PUBLIC_URL is on a different origin
- // from what our page is served on. This might happen if a CDN is used to
- // serve assets; see https://github.com/facebook/create-react-app/issues/2374
- return;
- }
+ if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) {
+ // The URL constructor is available in all browsers that support SW.
+ const publicUrl = new URL(process.env.PUBLIC_URL, window.location.href);
+ if (publicUrl.origin !== window.location.origin) {
+ // Our service worker won't work if PUBLIC_URL is on a different origin
+ // from what our page is served on. This might happen if a CDN is used to
+ // serve assets; see https://github.com/facebook/create-react-app/issues/2374
+ return;
+ }
- window.addEventListener('load', () => {
- const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`;
+ window.addEventListener('load', () => {
+ const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`;
- if (isLocalhost) {
- // This is running on localhost. Let's check if a service worker still exists or not.
- checkValidServiceWorker(swUrl, config);
+ if (isLocalhost) {
+ // This is running on localhost. Let's check if a service worker still exists or not.
+ checkValidServiceWorker(swUrl, config);
- // Add some additional logging to localhost, pointing developers to the
- // service worker/PWA documentation.
- navigator.serviceWorker.ready.then(() => {
- console.log(
- 'This web app is being served cache-first by a service ' +
- 'worker. To learn more, visit https://bit.ly/CRA-PWA'
- );
+ // Add some additional logging to localhost, pointing developers to the
+ // service worker/PWA documentation.
+ navigator.serviceWorker.ready.then(() => {
+ console.log("This web app is being served cache-first by a service worker. To learn more, visit https://bit.ly/CRA-PWA");
+ });
+ } else {
+ // Is not localhost. Just register service worker
+ registerValidSW(swUrl, config);
+ }
});
- } else {
- // Is not localhost. Just register service worker
- registerValidSW(swUrl, config);
- }
- });
- }
+ }
}
function registerValidSW(swUrl, config) {
- navigator.serviceWorker
- .register(swUrl)
- .then(registration => {
- registration.onupdatefound = () => {
- const installingWorker = registration.installing;
- if (installingWorker == null) {
- return;
- }
- installingWorker.onstatechange = () => {
- if (installingWorker.state === 'installed') {
- if (navigator.serviceWorker.controller) {
- // At this point, the updated precached content has been fetched,
- // but the previous service worker will still serve the older
- // content until all client tabs are closed.
- console.log(
- 'New content is available and will be used when all ' +
- 'tabs for this page are closed. See https://bit.ly/CRA-PWA.'
- );
+ navigator.serviceWorker
+ .register(swUrl)
+ .then(registration => {
+ registration.onupdatefound = () => {
+ const installingWorker = registration.installing;
+ if (installingWorker == null) {
+ return;
+ }
+ installingWorker.onstatechange = () => {
+ if (installingWorker.state === 'installed') {
+ if (navigator.serviceWorker.controller) {
+ // At this point, the updated precached content has been fetched,
+ // but the previous service worker will still serve the older
+ // content until all client tabs are closed.
+ console.log("New content is available and will be used when all tabs for this page are closed. See https://bit.ly/CRA-PWA.");
- // Execute callback
- if (config && config.onUpdate) {
- config.onUpdate(registration);
- }
- } else {
- // At this point, everything has been precached.
- // It's the perfect time to display a
- // "Content is cached for offline use." message.
- console.log('Content is cached for offline use.');
+ // Execute callback
+ if (config && config.onUpdate) {
+ config.onUpdate(registration);
+ }
+ } else {
+ // At this point, everything has been precached.
+ // It's the perfect time to display a
+ // "Content is cached for offline use." message.
+ console.log('Content is cached for offline use.');
- // Execute callback
- if (config && config.onSuccess) {
- config.onSuccess(registration);
- }
- }
- }
- };
- };
- })
- .catch(error => {
- console.error('Error during service worker registration:', error);
- });
+ // Execute callback
+ if (config && config.onSuccess) {
+ config.onSuccess(registration);
+ }
+ }
+ }
+ };
+ };
+ })
+ .catch(error => {
+ console.error('Error during service worker registration:', error);
+ });
}
function checkValidServiceWorker(swUrl, config) {
- // Check if the service worker can be found. If it can't reload the page.
- fetch(swUrl)
- .then(response => {
- // Ensure service worker exists, and that we really are getting a JS file.
- const contentType = response.headers.get('content-type');
- if (
- response.status === 404 ||
- (contentType != null && contentType.indexOf('javascript') === -1)
- ) {
- // No service worker found. Probably a different app. Reload the page.
- navigator.serviceWorker.ready.then(registration => {
- registration.unregister().then(() => {
- window.location.reload();
- });
- });
- } else {
- // Service worker found. Proceed as normal.
- registerValidSW(swUrl, config);
- }
- })
- .catch(() => {
- console.log(
- 'No internet connection found. App is running in offline mode.'
- );
+ // Check if the service worker can be found. If it can't reload the page.
+ fetch(swUrl).then(response => {
+ // Ensure service worker exists, and that we really are getting a JS file.
+ const contentType = response.headers.get('content-type');
+
+ if (response.status === 404 || (contentType != null && contentType.indexOf('javascript') === -1)) {
+ // No service worker found. Probably a different app. Reload the page.
+ navigator.serviceWorker.ready.then(registration => {
+ registration.unregister().then(() => {
+ window.location.reload();
+ });
+ });
+ } else {
+ // Service worker found. Proceed as normal.
+ registerValidSW(swUrl, config);
+ }
+ }).catch(() => {
+ console.log('No internet connection found. App is running in offline mode.');
});
}
export function unregister() {
- if ('serviceWorker' in navigator) {
- navigator.serviceWorker.ready.then(registration => {
- registration.unregister();
- });
- }
+ if ('serviceWorker' in navigator) {
+ navigator.serviceWorker.ready.then(registration => {
+ registration.unregister();
+ });
+ }
}
diff --git a/server/Dockerfile b/server/Dockerfile
index 07cf11df..dd94bba6 100644
--- a/server/Dockerfile
+++ b/server/Dockerfile
@@ -1,4 +1,4 @@
-FROM node:11
+FROM node:latest
RUN ln -fs /usr/share/zoneinfo/US/Pacific-New /etc/localtime && dpkg-reconfigure -f noninteractive tzdata
diff --git a/server/index.js b/server/index.js
index 38d1f452..4b5cd3b7 100644
--- a/server/index.js
+++ b/server/index.js
@@ -1,25 +1,27 @@
-const express = require('express');
-const mongoose = require('mongoose');
-const morgan = require('morgan');
-const bodyParser = require('body-parser');
+const express = require('express');
+const mongoose = require('mongoose');
+const morgan = require('morgan');
+const bodyParser = require('body-parser');
-const authRoutes = require('./routes/auth.routes');
-const routes = require('./routes/public.routes');
-const app = express();
-const port = 4000;
+const authRoutes = require('./routes/auth.routes');
+const routes = require('./routes/public.routes');
+const app = express();
+const port = 4000;
require('dotenv').config();
// DATABASE SETUP
// connect to db
-mongoose.connect(process.env.MONGODATABASE);
+mongoose.connect(process.env.MONGODATABASE, { useUnifiedTopology: true, useNewUrlParser: true, useCreateIndex: true});
+
// display message on connect
mongoose.connection.on('connected', () => {
- console.log('Connected to databse: ', process.env.MONGODATABASE);
+ console.log('Connected to databse: ', process.env.MONGODATABASE);
});
+
// display message on error
mongoose.connection.on('error', (err) => {
- console.log('Database error: ', err);
+ console.log('Database error: ', err);
});
// logger
@@ -27,17 +29,18 @@ app.use(morgan('dev'));
// bodyparser
app.use(bodyParser.json());
-app.use(bodyParser.urlencoded({ extended: false }));
+app.use(bodyParser.urlencoded({ extended: true }));
// CORS
// This allows client applications from other domains use the API Server
app.use((req, res, next) => {
- res.header('Access-Control-Allow-Credentials', 'true');
- res.header('Access-Control-Allow-Origin', '*');
- res.header('Access-Control-Expose-Headers', 'Authorization, refresh');
- res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept, Authorization, refresh');
- res.header('Access-Control-Allow-Methods', 'GET,POST,PUT,DELETE');
- next();
+ res.header('Access-Control-Allow-Credentials', 'true');
+ res.header('Access-Control-Allow-Origin', '*');
+ res.header('Access-Control-Expose-Headers', 'Authorization, refresh');
+ res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept, Authorization, refresh');
+ res.header('Access-Control-Allow-Methods', 'GET,POST,PUT,DELETE');
+
+ next();
});
// use routes
@@ -46,8 +49,8 @@ app.use('/api', routes);
// test route
app.get('/', (req, res) => {
- console.log('Hi!');
- res.send('Hi!');
+ console.log('Hi from expressjs server!');
+ res.send('Hi from expressjs server!');
})
app.listen(port, () => { console.log(`Listening on port ${port}`)});
\ No newline at end of file
diff --git a/server/models/order.model.js b/server/models/order.model.js
index ca6369ff..a79420b1 100644
--- a/server/models/order.model.js
+++ b/server/models/order.model.js
@@ -1,12 +1,13 @@
const mongoose = require('mongoose');
+// creating the database table. Should also include the user that signed in and link it to there account. user_id
const OrderSchema = new mongoose.Schema({
- order_item: String,
- quantity: Number,
- ordered_by: String,
+ order_item: String,
+ quantity: Number,
+ ordered_by: String
}, {
- timestamps: true,
- collection: 'Orders',
+ timestamps: true,
+ collection: 'Orders',
});
module.exports = mongoose.model('Order', OrderSchema);
\ No newline at end of file
diff --git a/server/package.json b/server/package.json
index d3eab038..2cfe53e0 100644
--- a/server/package.json
+++ b/server/package.json
@@ -11,10 +11,10 @@
"license": "ISC",
"dependencies": {
"body-parser": "^1.19.0",
- "dotenv": "^8.0.0",
+ "dotenv": "^10.0.0",
"express": "^4.17.1",
- "mongoose": "^5.7.7",
- "morgan": "^1.9.1"
+ "mongoose": "^5.12.15",
+ "morgan": "^1.10.0"
},
"devDependencies": {
"nodemon": "^1.19.1"
diff --git a/server/routes/auth.routes.js b/server/routes/auth.routes.js
index e85e1e69..74bdbf6b 100644
--- a/server/routes/auth.routes.js
+++ b/server/routes/auth.routes.js
@@ -1,19 +1,21 @@
-const express = require('express');
-
-const router = express.Router();
+const express = require('express');
+const router = express.Router();
// login expects email/password
// successful login returns email and a fake token (if we ever want to use it)
router.post('/login', (req, res) => {
- try {
- if (!req.body || !req.body.email || !req.body.password) {
- res.status(401).json({ success: false, error: 'Bad login information' });
- return;
+ try {
+ // if not content in body or email empty or password empty return bad login information
+ if (!req.body || !req.body.email || !req.body.password) {
+ res.status(401).json({ success: false, error: 'Bad login information' });
+ return;
+ }
+ // if login success return token with content
+ res.status(200).json({ success: true, email: req.body.email, token: '12345luggage' });
+ } catch (error) {
+ // server does not know what the problem is and we would have to debug
+ res.status(500).json({ success: false, error: 'Unknown error' });
}
- res.status(200).json({ success: true, email: req.body.email, token: '12345luggage' });
- } catch (error) {
- res.status(500).json({ success: false, error: 'Unknown error' });
- }
-})
+});
module.exports = router;
\ No newline at end of file
diff --git a/server/routes/public.routes.js b/server/routes/public.routes.js
index 8cf6d41d..7bfdecd3 100644
--- a/server/routes/public.routes.js
+++ b/server/routes/public.routes.js
@@ -1,129 +1,134 @@
-const express = require('express');
-const Order = require('../models/order.model');
-
-const router = express.Router();
+const express = require('express');
+const Order = require('../models/order.model');
+const router = express.Router();
+// test api to see if the api is working
router.get('/test', (req, res) => {
- console.log('Test endpoint hit!');
- res.json({ success: true });
+ console.log('Test endpoint hit!');
+ res.json({ success: true });
});
+// getting the list of the current orders. This is helpful for an admin panel because the worker can see all the orders. There needs to be a route based on the person that logins and can only see his orders
router.get('/current-orders', async (req, res) => {
- try {
- const orders = await Order.find();
- res.status(200).json({ success: true, orders });
- } catch (error) {
- res.status(500).json({ success: false, error });
- }
+ try {
+ const orders = await Order.find();
+ res.status(200).json({ success: true, orders });
+ } catch (error) {
+ res.status(500).json({ success: false, error });
+ }
});
+// create a new order
router.post('/add-order', async (req, res) => {
- try {
- if (!req.body) {
- res.status(400).json({ success: false, error: 'No information sent.' })
- return;
- }
-
- if (!req.body.order_item) {
- res.status(400).json({ success: false, error: 'No order item sent.'});
- return;
- }
-
- if (!req.body.quantity) {
- res.status(400).json({ success: false, error: 'No quantity sent.'})
- return;
- }
-
- const orderObj = new Order({
- order_item: req.body.order_item,
- quantity: req.body.quantity,
- ordered_by: req.body.ordered_by,
- });
-
- const dbResponse = await orderObj.save();
- if (dbResponse && dbResponse._id) {
- res.status(200).json({ success: true, insertedId: dbResponse._id });
- } else {
- res.status(400).json({ success: false, error: 'Database Error' });
+ try {
+ if (!req.body) {
+ res.status(400).json({ success: false, error: 'No information sent.' })
+ return;
+ }
+
+ if (!req.body.order_item) {
+ res.status(400).json({ success: false, error: 'No order item sent.'});
+ return;
+ }
+
+ if (!req.body.quantity) {
+ res.status(400).json({ success: false, error: 'No quantity sent.'})
+ return;
+ }
+ // creating the order object for posting
+ const orderObj = new Order({
+ order_item: req.body.order_item,
+ quantity: req.body.quantity,
+ ordered_by: req.body.ordered_by,
+ });
+
+ const dbResponse = await orderObj.save();
+
+ if (dbResponse && dbResponse._id) {
+ res.status(200).json({ success: true, insertedId: dbResponse._id });
+ } else {
+ res.status(400).json({ success: false, error: 'Database Error' });
+ }
+ } catch (error) {
+ res.status(500).json({ success: false, error });
}
- } catch (error) {
- res.status(500).json({ success: false, error });
- }
});
+// edit and order but it should not be a post. Need to switch to ".put"
router.post('/edit-order', async (req, res) => {
- // expects id
- try {
- if (!req.body.id) {
- res.status(400).json({ success: false, error: 'No id supplied'});
- return;
- }
-
- // make sure an order exists in the database with that id
- const targetOrder = await Order.findOne({ _id: req.body.id });
- if (!targetOrder) {
- res.status(400).json({ success: false, error: 'No order exists with that id!' });
- return;
- }
+ // expects id
+ try {
+ if (!req.body.id) {
+ res.status(400).json({ success: false, error: 'No id supplied'});
+ return;
+ }
+
+ // make sure an order exists in the database with that id
+ const targetOrder = await Order.findOne({ _id: req.body.id });
+ if (!targetOrder) {
+ res.status(400).json({ success: false, error: 'No order exists with that id!' });
+ return;
+ }
+
+ const updateResponse = await Order.updateOne({
+ _id: req.body.id
+ }, {
+ ordered_by: req.body.ordered_by,
+ order_item: req.body.order_item,
+ quantity: req.body.quantity
+ });
- const updateResponse = await Order.updateOne({
- _id: req.body.id
- }, {
- ordered_by: req.body.ordered_by,
- order_item: req.body.order_item,
- quantity: req.body.quantity,
- });
-
- if (!updateResponse || !updateResponse.nModified) {
- res.status(400).json({ success: false, error: 'Error in database while updating' });
- return;
+ if (!updateResponse || !updateResponse.nModified) {
+ res.status(400).json({ success: false, error: 'Error in database while updating' });
+ return;
+ }
+ res.status(200).json({ success: true });
+ } catch(error) {
+ res.status(500).json({ success: false, error });
}
- res.status(200).json({ success: true });
- } catch(error) {
- res.status(500).json({ success: false, error });
- }
});
+// delete an order and it needs to be ".delete" not post
router.post('/delete-order', async (req, res) => {
- try {
- // expects id
- if (!req.body.id) {
- res.status(400).json({ success: false, error: 'No id supplied' });
- return;
- }
+ try {
+ // expects id
+ if (!req.body.id) {
+ res.status(400).json({ success: false, error: 'No id supplied' });
+ return;
+ }
- // make sure an order exists in the database with that id
- const targetOrder = await Order.findOne({ _id: req.body.id });
- if (!targetOrder) {
- res.status(400).json({ success: false, error: 'No order exists with that id!' });
- return;
- }
+ // make sure an order exists in the database with that id
+ const targetOrder = await Order.findOne({ _id: req.body.id });
+ if (!targetOrder) {
+ res.status(400).json({ success: false, error: 'No order exists with that id!' });
+ return;
+ }
- const deleteResponse = await Order.deleteOne({ _id: req.body.id });
- if (!deleteResponse || !deleteResponse.n) {
- res.status(400).json({ success: false, error: 'Unable to delete from database' });
- return;
- }
+ const deleteResponse = await Order.deleteOne({ _id: req.body.id });
+ if (!deleteResponse || !deleteResponse.n) {
+ res.status(400).json({ success: false, error: 'Unable to delete from database' });
+ return;
+ }
- res.status(200).json({ success: true });
- } catch (error) {
- res.status(500).json({ success: false, error });
- }
+ res.status(200).json({ success: true });
+ } catch (error) {
+ res.status(500).json({ success: false, error });
+ }
});
+// delete all orders not just one.
router.delete('/delete-all', async (req, res) => {
- try {
- // HITTING THIS ENDPOINT DELETES ALL ORDERS
- const deleteResponse = await Order.deleteMany({});
- if (!deleteResponse) {
- res.status(400).json({ success: false, error: 'Error deleting all orders.' });
- return;
+ try {
+ // HITTING THIS ENDPOINT DELETES ALL ORDERS
+ const deleteResponse = await Order.deleteMany({});
+ if (!deleteResponse) {
+ res.status(400).json({ success: false, error: 'Error deleting all orders.' });
+ return;
+ }
+ res.status(200).json({ success: true, deleted: deleteResponse.n });
+ } catch (error) {
+ res.status(500).json({ success: false, error });
}
- res.status(200).json({ success: true, deleted: deleteResponse.n });
-
- } catch (error) {
- res.status(500).json({ success: false, error });
- }
});
module.exports = router;