├── .gitignore
├── Client
├── index.js
├── App.js
├── components
│ ├── BikeButton.jsx
│ ├── AddTask.jsx
│ ├── Task.jsx
│ └── TaskList.jsx
└── stylesheets
│ └── styles.scss
├── dist
├── server.generated.js.LICENSE.txt
├── bundle.js.LICENSE.txt
└── server.generated.js
├── nodemon.json
├── README.md
├── .babelrc
├── template.js
├── server
├── devBundle.js
├── models
│ └── motoModels.js
├── server.js
├── routes
│ └── api.js
└── controllers
│ └── motoController.js
├── webpack.config.client.production.js
├── webpack.config.server.js
├── webpack.config.client.js
└── package.json
/.gitignore:
--------------------------------------------------------------------------------
1 | /node_modules
2 | .env
3 | .DS_Store
4 | dump.rdb
--------------------------------------------------------------------------------
/Client/index.js:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 | import { render } from 'react-dom'
3 | import App from './App'
4 |
5 | render(, document.getElementById('root'))
--------------------------------------------------------------------------------
/dist/server.generated.js.LICENSE.txt:
--------------------------------------------------------------------------------
1 | /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
2 |
--------------------------------------------------------------------------------
/nodemon.json:
--------------------------------------------------------------------------------
1 | {
2 | "verbose": false,
3 | "watch": [ "./server" ],
4 | "exec": "webpack --mode=development --config webpack.config.server.js && node ./dist/server.generated.js"
5 | }
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # MotoMinder
2 |
3 | Welcome to MotoMinder!
4 |
5 | MotoMinder is used to help you keep track of your maintenance needs for your car or motorcycle.
6 | You can also keep track of your upgrades and categorize any of your 'to-do's' accordingly.
7 |
8 | Enjoy!
9 |
--------------------------------------------------------------------------------
/.babelrc:
--------------------------------------------------------------------------------
1 | {
2 | "presets": [
3 | ["@babel/preset-env",
4 | {
5 | "targets": {
6 | "node": "current"
7 | }
8 | }
9 | ],
10 | "@babel/preset-react"
11 | ],
12 | "plugins": [
13 | "react-hot-loader/babel"
14 | ]
15 | }
--------------------------------------------------------------------------------
/template.js:
--------------------------------------------------------------------------------
1 | export default () => {
2 | return `
3 |
4 |
5 |
6 | Solo
7 |
8 |
9 |
10 |
12 |
13 | `
14 | }
--------------------------------------------------------------------------------
/Client/App.js:
--------------------------------------------------------------------------------
1 | import { hot } from 'react-hot-loader/root';
2 | import './stylesheets/styles.scss'
3 | import React from 'react';
4 | import TaskList from './components/TaskList'
5 |
6 | const App = () => {
7 | return (
8 |
9 |
Motorcycle Maintanence and Upgrades
10 |
11 |
12 | )
13 | }
14 |
15 |
16 | export default hot(App) ;
--------------------------------------------------------------------------------
/Client/components/BikeButton.jsx:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import { hot } from 'react-hot-loader/root';
3 |
4 | const BikeButton = (props) => {
5 | let bikeString = `${props.thisBike.year} ${props.thisBike.make} ${props.thisBike.model}`;
6 | let classN = 'bikeButton';
7 | if (props.thisBike._id === props.currentBike._id) classN = 'currentBike'
8 | return(
9 |
10 |
11 |
12 | )
13 | }
14 |
15 |
16 | export default hot(BikeButton);
--------------------------------------------------------------------------------
/Client/components/AddTask.jsx:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import { hot } from 'react-hot-loader/root';
3 |
4 | const AddTask = (props) => {
5 | return(
6 |
7 |
8 |
12 |
13 |
14 |
15 | )
16 | }
17 |
18 |
19 | export default hot(AddTask);
--------------------------------------------------------------------------------
/server/devBundle.js:
--------------------------------------------------------------------------------
1 | import webpack from 'webpack'
2 | import webpackMiddleware from 'webpack-dev-middleware'
3 | import webpackHotMiddleware from 'webpack-hot-middleware'
4 | import webpackConfig from './../webpack.config.client.js'
5 |
6 |
7 | const compile = (app) => {
8 | if (process.env.NODE_ENV === "development") {
9 | const compiler = webpack(webpackConfig)
10 | const middleware = webpackMiddleware(compiler, {
11 | publicPath: webpackConfig.output.publicPath
12 | })
13 | app.use(middleware)
14 | app.use(webpackHotMiddleware(compiler))
15 | }
16 | }
17 | export default { compile }
--------------------------------------------------------------------------------
/server/models/motoModels.js:
--------------------------------------------------------------------------------
1 | const mongoose = require('mongoose');
2 | require('dotenv').config();
3 |
4 | // let uri = process.env.MONGO_URI
5 |
6 | mongoose.connect(process.env.MONGO_URI, {
7 | // options for the connect method to parse the URI
8 | useNewUrlParser: true,
9 | useUnifiedTopology: true,
10 | // sets the name of the DB that our collections are part of
11 | dbName: 'moto'
12 | })
13 | .then(() => console.log('Connected to Mongo DB.'))
14 | .catch(err => console.log(err));
15 |
16 | const Schema = mongoose.Schema;
17 |
18 | const taskSchema = new Schema({
19 | done: {type: Boolean, default: false},
20 | maint: {type: Boolean, required: true},
21 | task: {type: String, required: true},
22 | cost: Number,
23 | moto_id: {
24 | type: Schema.Types.ObjectId,
25 | ref: 'moto'
26 | }
27 | });
28 |
29 | const Task = mongoose.model('Task', taskSchema);
30 |
31 | const motoSchema = new Schema({
32 | year: Number,
33 | make: String,
34 | model: String,
35 | })
36 |
37 | const Moto = mongoose.model('Moto', motoSchema);
38 |
39 | module.exports = {
40 | Task,
41 | Moto
42 | }
43 |
44 |
--------------------------------------------------------------------------------
/webpack.config.client.production.js:
--------------------------------------------------------------------------------
1 | const path = require('path')
2 | const webpack = require('webpack')
3 | const CURRENT_WORKING_DIR = process.cwd()
4 | const config = {
5 | mode: 'production',
6 | entry: [path.join(CURRENT_WORKING_DIR, '/client/index.js')],
7 | output: {
8 | path: path.join(CURRENT_WORKING_DIR, '/dist'),
9 | filename: 'bundle.js',
10 | publicPath: '/dist/',
11 | },
12 | module: {
13 | rules: [
14 | {
15 | test: /\.jsx?$/,
16 | exclude: /node_modules/,
17 | use: {
18 | loader: 'babel-loader',
19 | options: {
20 | presets: ['@babel/preset-env', ['@babel/preset-react', {"runtime": "automatic"}]]
21 | }
22 | },
23 | },
24 | {
25 | test: /\.css$/i,
26 | use: ["style-loader", "css-loader"],
27 | },
28 | {
29 | test: /\.s[ac]ss$/i,
30 | use: ["style-loader", "css-loader", "sass-loader"]
31 | }
32 | ]
33 | },
34 |
35 | }
36 | module.exports = config
--------------------------------------------------------------------------------
/webpack.config.server.js:
--------------------------------------------------------------------------------
1 | const path = require('path')
2 | const webpack = require('webpack')
3 | const CURRENT_WORKING_DIR = process.cwd()
4 | const nodeExternals = require('webpack-node-externals')
5 | const config = {
6 | name: 'server',
7 | entry: [path.join(CURRENT_WORKING_DIR, './server/server.js')],
8 | target: 'node',
9 | output: {
10 | path: path.join(CURRENT_WORKING_DIR, '/dist/'),
11 | filename: 'server.generated.js',
12 | publicPath: '/dist/',
13 | libraryTarget: 'commonjs2'
14 | },
15 | externals: [nodeExternals()],
16 | module: {
17 | rules: [
18 | {
19 | test: /\.jsx?$/,
20 | exclude: /node_modules/,
21 | use: {
22 | loader: 'babel-loader',
23 | options: {
24 | presets: ['@babel/preset-env', ['@babel/preset-react', {"runtime": "automatic"}]]
25 | }
26 | },
27 | },
28 | {
29 | test: /\.css$/i,
30 | use: ["style-loader", "css-loader"],
31 | },
32 | {
33 | test: /\.s[ac]ss$/i,
34 | use: ["style-loader", "css-loader", "sass-loader"]
35 | }
36 | ]
37 | },
38 | }
39 | module.exports = config
--------------------------------------------------------------------------------
/dist/bundle.js.LICENSE.txt:
--------------------------------------------------------------------------------
1 | /*
2 | object-assign
3 | (c) Sindre Sorhus
4 | @license MIT
5 | */
6 |
7 | /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
8 |
9 | /** @license React v0.20.2
10 | * scheduler.production.min.js
11 | *
12 | * Copyright (c) Facebook, Inc. and its affiliates.
13 | *
14 | * This source code is licensed under the MIT license found in the
15 | * LICENSE file in the root directory of this source tree.
16 | */
17 |
18 | /** @license React v17.0.2
19 | * react-dom.production.min.js
20 | *
21 | * Copyright (c) Facebook, Inc. and its affiliates.
22 | *
23 | * This source code is licensed under the MIT license found in the
24 | * LICENSE file in the root directory of this source tree.
25 | */
26 |
27 | /** @license React v17.0.2
28 | * react-jsx-runtime.production.min.js
29 | *
30 | * Copyright (c) Facebook, Inc. and its affiliates.
31 | *
32 | * This source code is licensed under the MIT license found in the
33 | * LICENSE file in the root directory of this source tree.
34 | */
35 |
36 | /** @license React v17.0.2
37 | * react.production.min.js
38 | *
39 | * Copyright (c) Facebook, Inc. and its affiliates.
40 | *
41 | * This source code is licensed under the MIT license found in the
42 | * LICENSE file in the root directory of this source tree.
43 | */
44 |
--------------------------------------------------------------------------------
/Client/components/Task.jsx:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import { hot } from 'react-hot-loader/root';
3 |
4 | // THIS BREAKS HMR
5 | // import motoController from '../../server/controllers/motoController';
6 |
7 | const Task = (props) => {
8 | let type;
9 | let flag = props.task.done;
10 | let completed = [];
11 | if (flag === false) completed.push()
12 | else completed.push()
13 | type = props.task.maint ? 'Maintanence': 'Upgrade';
14 | let cost = props.task.cost.toLocaleString("en-US", {minimumFractionDigits: 2, maximumFractionDigits: 2});
15 |
16 | return(
17 |
18 |
19 | {completed}
20 |
21 |
{props.task.task}
22 |
{type}
23 |
$ {cost}
24 |
25 |
26 |
27 |
28 |
29 | )
30 | }
31 |
32 |
33 | export default hot(Task);
--------------------------------------------------------------------------------
/server/server.js:
--------------------------------------------------------------------------------
1 | import express from 'express'
2 | import devBundle from './devBundle'
3 | import path from 'path'
4 | import template from './../template'
5 | import { model } from 'mongoose'
6 | const app = express()
7 | devBundle.compile(app)
8 | const CURRENT_WORKING_DIR = process.cwd()
9 | const apiRouter = require('./routes/api')
10 | require('dotenv').config();
11 |
12 | const models = require('./models/motoModels')
13 |
14 | let port = process.env.PORT || 3000
15 |
16 | // handles parsing request body
17 | app.use(express.json());
18 | app.use(express.urlencoded({ extended: true }));
19 |
20 | // serves static bundle file
21 | app.use('/dist', express.static(path.join(CURRENT_WORKING_DIR, 'dist')))
22 |
23 | //routes requests to api
24 | app.use('/api', apiRouter)
25 |
26 | app.get('/',
27 | ((req, res) => {
28 | res.status(200).send(template())
29 | })
30 | )
31 |
32 | app.use((req, res) => res.status(404).send('Error 404: This page does not exist'));
33 |
34 | // Global Error Handler
35 | app.use((err, req, res, next) => {
36 | const defaultErr = {
37 | log: 'Express error handler caught unknown middleware error',
38 | status: 500,
39 | message: { err: 'An error occurred' },
40 | };
41 | const errorObj = Object.assign({}, defaultErr, err);
42 | console.log(errorObj.log);
43 | return res.status(errorObj.status).json(errorObj.message);
44 | });
45 |
46 |
47 | app.listen(port, (err) => {
48 | if (err) {
49 | console.log(err)
50 | }
51 | console.info('Server started on port %s.', port)
52 | })
--------------------------------------------------------------------------------
/server/routes/api.js:
--------------------------------------------------------------------------------
1 | const express = require('express');
2 |
3 | const motoController = require('../controllers/motoController');
4 |
5 | const router = express.Router();
6 |
7 | router.get('/tasks',
8 | motoController.getTasks,
9 | (req, res) => res.status(200).json(res.locals)
10 | )
11 |
12 | router.get('/bike',
13 | motoController.getBikes,
14 | (req, res) => res.status(200).json(res.locals)
15 | )
16 |
17 | router.get('/',
18 | motoController.getTasks,
19 | motoController.getBikes,
20 | (req, res) => res.status(200).json(res.locals)
21 | );
22 |
23 | router.post('/',
24 | motoController.addTask,
25 | (req, res) => res.status(200).json(`successfully added ${res.locals.task}`)
26 | );
27 |
28 | router.delete('/',
29 | motoController.deleteTask,
30 | (req, res) => res.status(200).json(`Successfully deleted ${res.locals.task}`)
31 | )
32 |
33 | router.patch('/',
34 | motoController.editTask,
35 | (req, res) => res.status(200).json('Successfully updated task')
36 | )
37 |
38 | router.post('/bike',
39 | motoController.addBike,
40 | (req, res) => res.status(200).json(res.locals.bike)
41 | )
42 |
43 | router.delete('/bike',
44 | motoController.deleteBike,
45 | (req, res) => res.status(200).json(`Successfully deleted ${res.locals.bike}`)
46 | )
47 |
48 | router.get('/all',
49 | motoController.getTasks,
50 | motoController.getBikes,
51 | (req, res) => res.status(200).json(res.locals)
52 | )
53 |
54 | router.get('/bikeImg/:query',
55 | motoController.getBikeImg,
56 | (req, res) => res.status(200).json(res.locals.bikeImg))
57 |
58 | module.exports = router;
--------------------------------------------------------------------------------
/webpack.config.client.js:
--------------------------------------------------------------------------------
1 | const path = require('path')
2 | const webpack = require('webpack')
3 | //const HtmlWebpackPlugin = require('html-webpack-plugin');
4 | const CURRENT_WORKING_DIR = process.cwd()
5 | const config = {
6 | name: 'browser',
7 | mode: 'development',
8 | devtool: 'eval-source-map',
9 | entry: [
10 | 'webpack-hot-middleware/client?reload=true',
11 | path.join(CURRENT_WORKING_DIR,'/client/index.js')
12 | ],
13 | output:{
14 | path: path.join(CURRENT_WORKING_DIR, '/dist'),
15 | filename: 'bundle.js',
16 | publicPath: '/dist/'
17 | },
18 | module:{
19 | rules: [
20 | {
21 | test: /\.jsx?$/,
22 | exclude: /node_modules/,
23 | use: {
24 | loader: 'babel-loader',
25 | options: {
26 | presets: ['@babel/preset-env', ['@babel/preset-react', {"runtime": "automatic"}]]
27 | }
28 | },
29 | },
30 | {
31 | test: /\.css$/i,
32 | use: ["style-loader", "css-loader"],
33 | },
34 | {
35 | test: /\.s[ac]ss$/i,
36 | use: ["style-loader", "css-loader", "sass-loader"]
37 | }
38 | ]
39 | },
40 | plugins: [
41 | new webpack.HotModuleReplacementPlugin(),
42 | new webpack.NoEmitOnErrorsPlugin()
43 | ],
44 | resolve:{
45 | alias:{
46 | 'react-dom': '@hot-loader/react-dom'
47 | },
48 | extensions: ['', '.js', '.jsx']
49 | }
50 | }
51 | module.exports = config
52 |
53 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "solo-project",
3 | "version": "1.0.0",
4 | "description": "Keeps track of motorcycle maintanence and upgrades as a list of to-do items",
5 | "main": "index.js",
6 | "scripts": {
7 | "test": "echo \"Error: no test specified\" && exit 1",
8 | "development": "nodemon",
9 | "build": "webpack --config webpack.config.client.production.js && webpack --mode=production --config webpack.config.server.js",
10 | "start": "NODE_ENV=production node ./dist/server.generated.js"
11 | },
12 | "repository": {
13 | "type": "git",
14 | "url": "git+https://github.com/GP3-RS/Solo-Project.git"
15 | },
16 | "author": "Gahl Peled",
17 | "license": "ISC",
18 | "bugs": {
19 | "url": "https://github.com/GP3-RS/Solo-Project/issues"
20 | },
21 | "dependencies": {
22 | "@hot-loader/react-dom": "^17.0.1",
23 | "axios": "^1.1.3",
24 | "dotenv": "^16.0.3",
25 | "express": "^4.17.2",
26 | "mongoose": "^5.11.9",
27 | "node-fetch": "^2.6.9",
28 | "react": "^17.0.2",
29 | "react-dom": "^17.0.2",
30 | "react-hot-loader": "^4.13.0",
31 | "react-router": "^4.3.1",
32 | "react-router-dom": "^4.3.1",
33 | "redis": "^4.6.5",
34 | "sass-loader": "^12.3.0"
35 | },
36 | "devDependencies": {
37 | "@babel/core": "^7.16.5",
38 | "@babel/preset-env": "^7.16.5",
39 | "@babel/preset-react": "^7.16.5",
40 | "babel-loader": "^8.2.3",
41 | "css-loader": "^6.7.2",
42 | "eslint": "^7.17.0",
43 | "eslint-plugin-react": "^7.21.5",
44 | "nodemon": "^2.0.15",
45 | "sass": "^1.56.1",
46 | "sass-loader": "^13.2.0",
47 | "style-loader": "^3.3.1",
48 | "webpack": "^5.75.0",
49 | "webpack-cli": "^4.9.1",
50 | "webpack-dev-middleware": "^5.3.0",
51 | "webpack-hot-middleware": "^2.25.1",
52 | "webpack-node-externals": "^3.0.0"
53 | },
54 | "homepage": "https://github.com/GP3-RS/Solo-Project#readme"
55 | }
56 |
--------------------------------------------------------------------------------
/server/controllers/motoController.js:
--------------------------------------------------------------------------------
1 | const models = require('../models/motoModels');
2 | const redis = require('redis');
3 | const fetch = (...args) => import('node-fetch').then(({default: fetch}) => fetch(...args))
4 |
5 | let redisClient;
6 |
7 | const motoController = {};
8 |
9 | (async () => {
10 | redisClient = redis.createClient();
11 | redisClient.on("connect", () => console.log('Connected to Redis cache successfully.'))
12 | redisClient.on("error", (error) => console.error(`Error : ${error}`));
13 | await redisClient.connect();
14 | })();
15 |
16 | motoController.addTask = async (req, res, next) => {
17 | let { maint, task, cost, moto_id } = req.body
18 | if (cost === undefined) cost = 0;
19 | cost = Number(cost);
20 | try {
21 | let returnedTask = await models.Task.create({
22 | maint: maint,
23 | task: task,
24 | cost: cost,
25 | moto_id: moto_id,
26 | })
27 | res.locals.task = returnedTask;
28 | return next();
29 | }
30 | catch (err) {
31 | next({log: 'error in middleware addTask', message: 'error in addTask'})
32 | }
33 | }
34 |
35 | motoController.getTasks = (req, res, next) => {
36 | models.Task.find({})
37 | .exec()
38 | .then(data => {
39 | res.locals.tasks = data;
40 | return next();
41 | })
42 | .catch(err => next({log: 'error in middleware getTasks', message: 'error in getTasks'}))
43 | }
44 |
45 | motoController.deleteTask = (req, res, next) => {
46 | const id = req.body.id;
47 | models.Task.findOneAndDelete({_id: id})
48 | .exec()
49 | .then(data => {
50 | res.locals.task = data.task;
51 | return next();
52 | })
53 | .catch(err => next({log: "error in middleware deleteTask", message: 'error in middleware deleteTask'}))
54 | }
55 |
56 | motoController.editTask = (req, res, next) => {
57 | const { id, done, newTask } = req.body;
58 | if (newTask !== undefined) {
59 | const { id, newTask } = req.body;
60 | models.Task.updateOne({_id: id}, {
61 | task: newTask
62 | })
63 | .exec()
64 | .then(data => {
65 | return next()})
66 | .catch(err => next({log: "error in middleware editTask", message: "error in middleware editTask"}))
67 | }
68 | if (done === false || done === true) {
69 | models.Task.updateOne({_id: id}, {
70 | done: done
71 | })
72 | .exec()
73 | .then(data => {
74 | return next()})
75 | .catch(err => next({log: "error in middleware editTask", message: "error in middleware editTask"}))
76 | }
77 | }
78 |
79 | motoController.getBikes = (req, res, next) => {
80 | models.Moto.find({})
81 | .exec()
82 | .then(data => {
83 | res.locals.bikes = data;
84 | return next();
85 | })
86 | .catch(err => next({log: 'error in middleware getBikes', message: 'error in getMoto'}))
87 | }
88 |
89 | motoController.addBike = async (req, res, next) => {
90 | let { year, make, model } = req.body
91 | year = Number(year)
92 | try {
93 | let returnedMoto = await models.Moto.create({
94 | year: year,
95 | make: make,
96 | model: model,
97 | })
98 | res.locals.bike = returnedMoto;
99 | return next()
100 | }
101 | catch(err) {
102 | next({log: 'error in middleware addBike', message: 'error in addBike'})}
103 | }
104 |
105 | motoController.deleteBike = (req, res, next) => {
106 | const id = req.body.id;
107 | models.Moto.findOneAndDelete({_id: id})
108 | .exec()
109 | .then(bike => res.locals.bike = bike)
110 | .catch(err => next({log: 'error in middleware deletBike', message: 'error in middleware deleteBike'}))
111 | models.Task.remove({moto_id: id})
112 | .exec()
113 | .catch(err => next({log: 'error in middleware deletBike', message: 'error in middleware deleteBike'}))
114 | }
115 |
116 | motoController.getBikeImg = async (req, res, next) => {
117 | let start = Date.now();
118 | const { query } = req.params;
119 | const value = await redisClient.get(query);
120 | if (value) {
121 | console.log('cache hit');
122 | res.locals.bikeImg = value;
123 | console.log('time to return results: ', Date.now() - start);
124 | return next();
125 | }
126 | else await fetch(process.env.GOOGLE_API + req.params.query)
127 | .then(data => data.json())
128 | .then(data => {
129 | if (data) {
130 | console.log('cache miss');
131 | redisClient.set(query, data.items[0].pagemap.cse_image[0].src, 'EX', 10, (err, result) => {
132 | if (err) {
133 | console.error(err);
134 | }
135 | else console.log('Key set: ', result);
136 | });
137 | res.locals.bikeImg = data;
138 | console.log('time to return results: ', Date.now() - start);
139 | return next();
140 | }
141 | else return next({message: 'ERROR: Google API fetch request failed, likely because you have surpassed your daily limit of queries. Error message', log: 'Google API fetch failed'})
142 | })
143 | .catch(err => next({message: 'ERROR: Google API fetch request failed, likely because you have surpassed your daily limit of queries. Exact message received by server is: ' + err.message, log: 'Google API fetch failed and caught by catch block'}))
144 | }
145 |
146 |
147 |
148 | module.exports = motoController;
149 |
--------------------------------------------------------------------------------
/Client/stylesheets/styles.scss:
--------------------------------------------------------------------------------
1 | @import url('https://fonts.googleapis.com/css2?family=Montserrat:wght@500&family=Poppins:wght@300&family=Roboto&family=Scada&family=Work+Sans:wght@200;400;500;800&display=swap');
2 |
3 | $primary-light: rgb(249, 249, 249);
4 | $secondary-light: rgb(235, 242, 250);
5 | $primary-dark: black;
6 | $secondary-dark: rgb(50, 50, 50);
7 | $primary-color-light: rgb(232, 233, 237);
8 | $primary-color-med: rgb(76, 134, 168);
9 | $primary-color-dark:rgb(61, 43, 61);
10 | $font1: Work Sans;
11 | $font2: Poppins;
12 |
13 |
14 | body {
15 | background-color: $primary-light;
16 | display: flex;
17 | width: 100%;
18 | max-width: 100%;
19 | margin: 0;
20 | height: 100%;
21 | max-height: 100%;
22 | justify-content: center;
23 | font-family: $font1;
24 | font-weight: 400;
25 | font-size: 18px;
26 | color:$secondary-dark;
27 | cursor: default;
28 | }
29 |
30 | #root {
31 | margin-top: 20px;
32 | display: flex;
33 | justify-content: center;
34 | max-width: 95%;
35 | width: 95%;
36 | }
37 |
38 | .mainDiv {
39 | display: flex;
40 | flex-direction: column;
41 | max-width: 100%;
42 | flex-basis: 80%;
43 | }
44 |
45 | h1 {
46 | text-align: center
47 | }
48 |
49 | .addTask {
50 | display: flex;
51 | justify-content: space-evenly;
52 | gap: 1em;
53 | margin-bottom: 50px;
54 | margin-top: 30px;
55 | height: 50px;
56 | align-items: stretch;
57 | }
58 |
59 | #taskInput {
60 | border-radius: 7px;
61 | border: 1px solid $secondary-light;
62 | width: 75%;
63 | height: 2rem;
64 | padding-left: 5px;
65 | color: $primary-color-med;
66 | font-size: 18px;
67 | height: 100%;
68 |
69 | &:hover {
70 | border: 1px solid $primary-color-light;
71 | }
72 |
73 | &:focus {
74 | outline: none;
75 | }
76 | }
77 |
78 | #addButton {
79 | width: 10%;
80 | background-color: $primary-color-light;
81 | color: $primary-color-dark;
82 | border-radius: 7px;
83 | font-size: 16px;
84 | font-weight: 600;
85 | border: 1px solid $primary-color-light;
86 |
87 | &:hover {
88 | background-color: $primary-color-med;
89 | cursor: pointer;
90 | border: 1px solid $primary-color-med;
91 | color: $secondary-light;
92 | }
93 |
94 | &:active {
95 | background-color: $primary-color-dark;
96 | cursor: pointer;
97 | border: 1px solid $primary-color-dark;
98 | color: $primary-light;
99 | }
100 | }
101 |
102 | .task {
103 | display: flex;
104 | gap: 20px;
105 | flex-direction: row;
106 | width: 100%;
107 | max-width: 100%;
108 | align-items: center;
109 | border-radius: 14px;
110 | font-family: $font2;
111 |
112 | &:hover {
113 | background-color: $primary-color-light;
114 | }
115 | }
116 |
117 | #costInput {
118 | width: 10%;
119 | min-width: 59px;
120 | border: 1px solid $secondary-light;
121 | border-radius: 7px;
122 | outline: none;
123 | font-size: 18px;
124 | color: $primary-color-med;
125 |
126 | &:hover {
127 | border: 1px solid $primary-color-light;
128 | }
129 | }
130 |
131 | label {
132 | display: flex;
133 | flex-direction: column;
134 |
135 | input {
136 | width: 20px;
137 | height: 20px;
138 | align-self: center;
139 | border: 1px solid $primary-light;
140 | outline: none;
141 | }
142 |
143 | &:hover {
144 | cursor: pointer;
145 | }
146 |
147 | &:active {
148 | color: $primary-color-med;
149 | }
150 | }
151 |
152 | .columns {
153 | display: flex;
154 | gap: 20px;
155 | white-space: nowrap;
156 | font-size: 22px;
157 | }
158 |
159 | .completedRadio {
160 | width: 132px;
161 | height: 20px;
162 | cursor: pointer;
163 | }
164 |
165 | .taskText {
166 | display: flex;
167 | flex-basis: 40%;
168 | max-width: 40%;
169 | flex-wrap: wrap;
170 | flex-grow: 1;
171 | min-width: 127px;
172 | }
173 |
174 | #taskName {
175 | display: flex;
176 | justify-content: center;
177 | flex-basis: 40%;
178 | max-width: 40%;
179 | flex-grow: 1;
180 | }
181 |
182 | .costValue {
183 | display: flex;
184 | flex-grow: 1;
185 | flex-wrap: nowrap;
186 | justify-content: center;
187 | white-space: nowrap;
188 | }
189 |
190 | #optionsColumn {
191 | display: flex;
192 | justify-content: center;
193 | flex-basis: 10%;
194 | flex-grow: 1;
195 | min-width: 133px;
196 | }
197 |
198 | .options {
199 | display: flex;
200 | justify-content: center;
201 | flex-basis: 10%;
202 | gap: 1em;
203 | flex-grow: 1;
204 | flex-wrap: nowrap;
205 | right: 0;
206 |
207 | button {
208 | max-width: 100%;
209 | background-color: $primary-color-light;
210 | color: $primary-color-dark;
211 | border-radius: 7px;
212 | font-size: 16px;
213 | font-weight: 600;
214 | border: 1px solid $primary-color-light;
215 |
216 | &:hover {
217 | background-color: $primary-color-med;
218 | cursor: pointer;
219 | border: 1px solid $primary-color-med;
220 | color: $secondary-light;
221 | }
222 |
223 | &:active {
224 | background-color: $primary-color-dark;
225 | cursor: pointer;
226 | border: 1px solid $primary-color-dark;
227 | color: $primary-light;
228 | }
229 | }
230 | }
231 |
232 | #taskType {
233 | width: 10%;
234 | text-align: center;
235 | min-width: fit-content;
236 | }
237 |
238 | .taskTypeValue {
239 | width: 10%;
240 | text-align: center;
241 | min-width: 110px;
242 | }
243 |
244 | #costColumn {
245 | display: flex;
246 | flex-grow: 1;
247 | justify-content: center;
248 | }
249 |
250 | #noTasks {
251 | text-align: center;
252 | color: $primary-color-light;
253 | }
254 |
255 | .stats {
256 | display: flex;
257 | flex-direction: column;
258 | justify-content: space-evenly;
259 | font-size: 18px;
260 | color: $primary-color-med;
261 |
262 | &:hover {
263 | color: $primary-color-dark;
264 | cursor: default;
265 | }
266 | }
267 |
268 | .completedTask {
269 | display: flex;
270 | gap: 20px;
271 | flex-direction: row;
272 | width: 100%;
273 | max-width: 100%;
274 | align-items: center;
275 | border-radius: 14px;
276 | font-family: $font2;
277 | color: $primary-color-dark;
278 |
279 | &:hover {
280 | background-color: $primary-color-light;
281 | color: $primary-color-dark
282 | }
283 | }
284 |
285 | hr {
286 | fill: $primary-color-med;
287 | border: 1px solid $primary-color-light;
288 | outline: 1px solid $primary-color-light;
289 | }
290 |
291 | .bikeButton {
292 | // margin-top: 20px;
293 | padding: 5px;
294 | background-color: $primary-color-light;
295 | border: none;
296 | font-size: 18px;
297 | font-family: $font2;
298 | border-radius: 7px;
299 | min-height: fit-content;
300 |
301 | &:hover {
302 | background-color: $primary-color-med;
303 | cursor: pointer;
304 | color: $secondary-light;
305 | }
306 |
307 | &:active {
308 | background-color: $primary-color-dark;
309 | cursor: pointer;
310 | color: $primary-light;
311 | }
312 | }
313 |
314 | .currentBike {
315 | // margin-top: 20px;
316 | padding: 5px;
317 | background-color: $primary-color-dark;
318 | border: none;
319 | font-size: 18px;
320 | font-family: $font2;
321 | border-radius: 7px;
322 | min-height: fit-content;
323 | color: $primary-light;
324 |
325 | &:hover {
326 | background-color: $primary-color-med;
327 | cursor: pointer;
328 | color: $secondary-light;
329 | }
330 |
331 | &:active {
332 | background-color: $primary-color-dark;
333 | cursor: pointer;
334 | color: $primary-light;
335 | }
336 | }
337 |
338 | #deleteBike {
339 | margin-top: 20px;
340 | padding: 5px;
341 | background-color: rgb(181, 101, 118);
342 | border: none;
343 | font-size: 18px;
344 | font-family: $font2;
345 | border-radius: 7px;
346 | min-height: fit-content;
347 | color: $primary-light;
348 |
349 | &:hover {
350 | background-color: rgb(161, 7, 7);
351 | cursor: pointer;
352 | color: white;
353 | }
354 |
355 | &:active {
356 | background-color: $primary-color-dark;
357 | cursor: pointer;
358 | border: 1px solid $primary-color-dark;
359 | color: $primary-light;
360 | }
361 | }
362 |
363 |
364 |
365 | .prompt {
366 | display: none;
367 | height: 49px;
368 | justify-content: space-between;
369 |
370 | input {
371 | border-radius: 7px;
372 | border: 1px solid $secondary-light;
373 | width: 20%;
374 | height: 2rem;
375 | padding-left: 5px;
376 | color: $primary-color-med;
377 | font-size: 18px;
378 | height: 100%;
379 |
380 | }
381 |
382 | #addBikeButton:hover {
383 | cursor: pointer;
384 | }
385 | }
386 |
387 | .bikeButtons {
388 | display: flex;
389 | flex-direction: column;
390 | align-items: flex-start;
391 | margin-left: 20px;
392 |
393 | div {
394 | display: flex;
395 | gap: 1em;
396 | flex-wrap: wrap;
397 | }
398 |
399 | p {
400 | font-size: 14px;
401 | }
402 | }
403 |
404 | #bikeContainer {
405 | display: flex;
406 | align-items: center;
407 | }
408 |
409 | .bikeImg {
410 | max-width: 50%;
411 | align-self: center;
412 | border-radius: 10px;
413 | -webkit-mask-image: -webkit-gradient(linear, left top,
414 | left bottom, from(rgba(0,0,0,1)), to(rgba(0,0,0,0)));
415 | }
416 |
417 |
418 | #bigContainer {
419 | display: flex;
420 | flex-direction: column;
421 | }
422 |
423 | hr {
424 | min-width: 100%;
425 | }
--------------------------------------------------------------------------------
/Client/components/TaskList.jsx:
--------------------------------------------------------------------------------
1 | import React, {useState, useEffect} from 'react';
2 | import { hot } from 'react-hot-loader/root';
3 | import Task from './Task.jsx'
4 | import AddTask from './AddTask.jsx';
5 | import BikeButton from './bikeButton.jsx';
6 |
7 | const TaskList = () => {
8 |
9 | const [bikeImg, setImg] = useState('https://media.tenor.com/On7kvXhzml4AAAAj/loading-gif.gif');
10 | const [currentBike, setCurrentBike] = useState(null);
11 | const [bikes, setBikes] = useState([]);
12 | const [tasks, setTasks] = useState([]);
13 | const [loading, setLoading] = useState(true);
14 | const [imgCache, setImgCache] = useState({});
15 |
16 |
17 | useEffect(() => {
18 | fetch('/api/all')
19 | .then(res => res.json())
20 | .then(data => {
21 | setTasks(data.tasks);
22 | setBikes(data.bikes);
23 | setCurrentBike(data.bikes[0]);
24 | })
25 | }, [])
26 |
27 | useEffect(async () => {
28 | setLoading(true);
29 | if (currentBike) {
30 | let query = `${currentBike.year}+${currentBike.make}+${currentBike.model}`.replace(/\s/g, '+')
31 | if (imgCache[query]) setImg(imgCache[query]);
32 | else await fetch(`/api/BikeImg/${query}`)
33 | .then(res => res.json())
34 | .then(img => {
35 | setImg(img);
36 | setImgCache({...imgCache, query: img})
37 | })
38 | .catch(err => console.log(err.toString()));
39 | }
40 | setLoading(false);
41 | }, [currentBike])
42 |
43 | const addTask = async(event) => {
44 | if (!currentBike) {
45 | window.alert('You must add a bike first');
46 | throw new Error('You must add a bike first');
47 | }
48 | let task = event.target.previousSibling.previousSibling.previousSibling.value;
49 | let maint = event.target.previousSibling.previousSibling.lastChild.checked;
50 | let cost = event.target.previousSibling.value;
51 | if (cost === '') cost = 0;
52 | cost = cost.replace(/\,/g,'');
53 | cost = cost.split('.');
54 | if (!cost.every(el => (/^\d+$/.test(el))) || cost.length > 2) {
55 | window.alert('Cost must be a number with no more than one decimal');
56 | throw new Error('Cost must be a number');
57 | }
58 | cost = cost.join('.');
59 | if (task === '') throw new Error('You must input something into the text field before adding a task. It cannot be left blank');
60 | cost = cost.toLocaleString("en-US", {
61 | minimumFractionDigits: 2,
62 | maximumFractionDigits: 2
63 | });
64 |
65 | setTasks(tasks.concat({done: false, maint, task, cost}))
66 |
67 | await fetch('/api', {
68 | method: 'POST',
69 | headers: {
70 | 'Content-Type': 'application/json'
71 | },
72 | body: JSON.stringify(
73 | {
74 | maint: maint,
75 | task: task,
76 | cost: cost,
77 | moto_id: currentBike._id,
78 | }
79 | )
80 | })
81 | .catch(err => console.error('error with POST FETCH @ Add Button'))
82 |
83 | fetch('/api/tasks')
84 | .then(res => res.json())
85 | .then(data => {
86 | return setTasks(data.tasks)
87 | })
88 |
89 | event.target.previousSibling.previousSibling.previousSibling.value = '';
90 | event.target.previousSibling.value = '';
91 | event.target.previousSibling.previousSibling.lastChild.checked = false;
92 | }
93 |
94 | const deleteTask = async (event) => {
95 |
96 | const id = event.target.parentNode.parentNode.id;
97 | let index;
98 | for (let i = 0; i < tasks.length; i++) {
99 | if (tasks[i]._id === id) index = i;
100 | }
101 |
102 | setTasks(tasks.filter(el => {
103 | return tasks.indexOf(el) !== index;
104 | }))
105 |
106 |
107 | await fetch('/api', {
108 | method: 'DELETE',
109 | headers: {
110 | 'Content-Type': 'application/json'
111 | },
112 | body: JSON.stringify({id})
113 | })
114 | .then(data => data.json())
115 | .then(data => console.log(data))
116 | .catch(err => console.error('error with DELETE FETCH'))
117 | }
118 |
119 | const editTask = async (event) => {
120 | let currentTask = event.target.parentNode.previousSibling.previousSibling.previousSibling.textContent;
121 | let newTask = window.prompt('Edit your task: ', currentTask);
122 |
123 | const id = event.target.parentNode.parentNode.id;
124 |
125 | setTasks(tasks.map(el => {
126 | if (el._id === id) {
127 | return {
128 | ...el,
129 | task: newTask,
130 | }
131 | }
132 | else return el;
133 | }))
134 |
135 | await fetch('/api', {
136 | method: 'PATCH',
137 | headers: {
138 | 'Content-Type': 'application/json'
139 | },
140 | body: JSON.stringify({id, newTask})
141 | })
142 | .then(data => data.json())
143 | .then(data => console.log(data))
144 | .catch(err => console.error('error with PATCH FETCH'))
145 | }
146 |
147 |
148 | const completeTask = async (event) => {
149 | let value = event.target.checked;
150 | const id = event.target.parentNode.parentNode.id;
151 |
152 | setTasks(tasks.map(el => {
153 | if (el._id === id) {
154 | return {
155 | ...el,
156 | done: value,
157 | }
158 | }
159 | else return el;
160 | }))
161 |
162 | await fetch('/api', {
163 | method: 'PATCH',
164 | headers: {
165 | 'Content-Type': 'application/json'
166 | },
167 | body: JSON.stringify({id, done: value})
168 | })
169 | .then(data => data.json())
170 | .then(data => console.log(data))
171 | .catch(err => console.error('error with PATCH FETCH'))
172 | }
173 |
174 | const promptBike = (event) => {
175 | document.querySelector('#addNewBikeButton').style.display = 'none';
176 | document.querySelector('.prompt').style.display = 'flex';
177 | }
178 |
179 | const addBike = async (event) => {
180 |
181 | let year = event.target.previousSibling.previousSibling.previousSibling.value;
182 | let make = event.target.previousSibling.previousSibling.value;
183 | let model = event.target.previousSibling.value;
184 | if (year === '' || make === '' || model === '') throw new Error('In order to adda bike, you must input something for year, make, and model')
185 |
186 | if (!(/^\d+$/.test(year))) {
187 | window.alert('Year must be a number');
188 | throw new Error('Year must be a number');
189 | }
190 |
191 | let bikeObj = {
192 | year: year,
193 | make: make,
194 | model: model
195 | }
196 |
197 | setCurrentBike(bikeObj);
198 | setBikes(bikes.concat(bikeObj));
199 |
200 |
201 | document.querySelector('.prompt').style.display = 'none';
202 | document.querySelector('#addNewBikeButton').style.display = 'flex';
203 | event.target.previousSibling.previousSibling.previousSibling.value = '';
204 | event.target.previousSibling.previousSibling.value = '';
205 | event.target.previousSibling.value = '';
206 |
207 | await fetch('/api/bike', {
208 | method: 'POST',
209 | headers: {
210 | 'Content-Type': 'application/json'
211 | },
212 | body: JSON.stringify(
213 | {
214 | year: year,
215 | make: make,
216 | model: model,
217 | }
218 | )
219 | })
220 | .then(res => res.json())
221 | .then(data => {
222 | return setCurrentBike(data);
223 | })
224 | .catch(err => console.error('error with POST FETCH @ Add Button'))
225 |
226 | await fetch('/api/bike')
227 | .then(res => res.json())
228 | .then(data => {
229 | return setBikes(data.bikes)
230 | })
231 | }
232 |
233 | const changeBike = async (event) => {
234 |
235 | if (event.target.id === currentBike._id) return;
236 |
237 | setCurrentBike(bikes.filter(el => {
238 | return el._id === event.target.id;
239 | })[0])
240 | }
241 |
242 | const deleteBike = async (event) => {
243 | let confirm = window.confirm(`Current bike: ${currentBike.year} ${currentBike.make} ${currentBike.model}\n \nAre you sure you want to delete this bike?\n \n This will delete all of its tasks as well. This cannot be undone`)
244 |
245 | let id = currentBike._id
246 |
247 | if (confirm === true) {
248 | setCurrentBike(bikes.filter(el => {
249 | return el._id !== currentBike._id;
250 | })[0])
251 | setBikes(bikes.filter(el => {
252 | return el._id !== currentBike._id;
253 | }))
254 |
255 | await fetch('/api/bike', {
256 | method: 'DELETE',
257 | headers: {
258 | 'Content-Type': 'application/json'
259 | },
260 | body: JSON.stringify({id})
261 | })
262 | .then(data => data.json())
263 | .then(data => console.log(data))
264 | .catch(err => console.error('error with DELETE FETCH'))
265 | }
266 | }
267 |
268 | const tasksArr = [];
269 | const completedArr = [];
270 | const bikeButtonsArr = [];
271 | let activeTasks = 0;
272 | let completedTasks = 0;
273 | let totalCost = 0;
274 | let totalSpent = 0;
275 | let currentBikeString = 'Current bike: ';
276 |
277 | if (currentBike) {
278 | for (let i = 0; i < tasks.length; i++) {
279 | let number = -1 - i;
280 | if (tasks[i].moto_id === currentBike._id && tasks[i].done === false) {
281 | tasksArr.push();
282 | totalCost += tasks[i].cost;
283 | activeTasks++;
284 | }
285 | else if (tasks[i].moto_id === currentBike._id) {
286 | completedArr.push()
287 | totalSpent += tasks[i].cost;
288 | completedTasks++;
289 | }
290 | }
291 |
292 | currentBikeString = `Current bike is: ${currentBike.year} ${currentBike.make} ${currentBike.model}`
293 |
294 | for (let i = 0; i < bikes.length; i++) {
295 | let keyString = `${bikes[i].year}${bikes[i].make}${bikes[i].model}`
296 | bikeButtonsArr.push()
297 | }
298 | }
299 |
300 | return(
301 |
302 |
303 |
304 |
305 |
306 |
307 |
308 |
309 |
310 |
311 |
{currentBikeString}
312 |
313 | {bikeButtonsArr}
314 |
315 |
316 |
317 |
318 |
Total Incomplete Tasks: {activeTasks}
319 |
Total Cost: $ {totalCost.toLocaleString("en-US", {minimumFractionDigits: 2, maximumFractionDigits: 2})}
320 |
321 |
322 |
Completed?
323 |
Task Name
324 |
Task Type
325 |
Cost
326 |
Options
327 |
328 |
329 | {tasks.length ?
330 | tasksArr
331 | :
332 |
You don't have any tasks. Add one using the input box above.
}
333 |
334 |
335 |
336 |
Completed Tasks
337 |
Total Completed Tasks: {completedTasks}
338 |
Total Spent: $ {totalSpent.toLocaleString("en-US", {minimumFractionDigits: 2, maximumFractionDigits: 2})}
339 |
Uncheck to revert back to incomplete
340 | {completedArr}
341 |
342 | {loading ?
:
}
343 |
344 | )
345 | }
346 |
347 |
348 | export default hot(TaskList);
--------------------------------------------------------------------------------
/dist/server.generated.js:
--------------------------------------------------------------------------------
1 | /*
2 | * ATTENTION: The "eval" devtool has been used (maybe by default in mode: "development").
3 | * This devtool is neither made for production nor for readable output files.
4 | * It uses "eval()" calls to create a separate source file in the browser devtools.
5 | * If you are trying to read the output file, select a different devtool (https://webpack.js.org/configuration/devtool/)
6 | * or disable the default devtool with "devtool: false".
7 | * If you are looking for production-ready output files, see mode: "production" (https://webpack.js.org/configuration/mode/).
8 | */
9 | /******/ (() => { // webpackBootstrap
10 | /******/ var __webpack_modules__ = ({
11 |
12 | /***/ "./server/controllers/motoController.js":
13 | /*!**********************************************!*\
14 | !*** ./server/controllers/motoController.js ***!
15 | \**********************************************/
16 | /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
17 |
18 | eval("/* module decorator */ module = __webpack_require__.nmd(module);\nfunction _typeof(obj) { \"@babel/helpers - typeof\"; return _typeof = \"function\" == typeof Symbol && \"symbol\" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && \"function\" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? \"symbol\" : typeof obj; }, _typeof(obj); }\n(function () {\n var enterModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.enterModule : undefined;\n enterModule && enterModule(module);\n})();\nfunction _regeneratorRuntime() { \"use strict\"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, defineProperty = Object.defineProperty || function (obj, key, desc) { obj[key] = desc.value; }, $Symbol = \"function\" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || \"@@iterator\", asyncIteratorSymbol = $Symbol.asyncIterator || \"@@asyncIterator\", toStringTagSymbol = $Symbol.toStringTag || \"@@toStringTag\"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, \"\"); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return defineProperty(generator, \"_invoke\", { value: makeInvokeMethod(innerFn, self, context) }), generator; } function tryCatch(fn, obj, arg) { try { return { type: \"normal\", arg: fn.call(obj, arg) }; } catch (err) { return { type: \"throw\", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { [\"next\", \"throw\", \"return\"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if (\"throw\" !== record.type) { var result = record.arg, value = result.value; return value && \"object\" == _typeof(value) && hasOwn.call(value, \"__await\") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke(\"next\", value, resolve, reject); }, function (err) { invoke(\"throw\", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke(\"throw\", error, resolve, reject); }); } reject(record.arg); } var previousPromise; defineProperty(this, \"_invoke\", { value: function value(method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(innerFn, self, context) { var state = \"suspendedStart\"; return function (method, arg) { if (\"executing\" === state) throw new Error(\"Generator is already running\"); if (\"completed\" === state) { if (\"throw\" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if (\"next\" === context.method) context.sent = context._sent = context.arg;else if (\"throw\" === context.method) { if (\"suspendedStart\" === state) throw state = \"completed\", context.arg; context.dispatchException(context.arg); } else \"return\" === context.method && context.abrupt(\"return\", context.arg); state = \"executing\"; var record = tryCatch(innerFn, self, context); if (\"normal\" === record.type) { if (state = context.done ? \"completed\" : \"suspendedYield\", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } \"throw\" === record.type && (state = \"completed\", context.method = \"throw\", context.arg = record.arg); } }; } function maybeInvokeDelegate(delegate, context) { var method = delegate.iterator[context.method]; if (undefined === method) { if (context.delegate = null, \"throw\" === context.method) { if (delegate.iterator[\"return\"] && (context.method = \"return\", context.arg = undefined, maybeInvokeDelegate(delegate, context), \"throw\" === context.method)) return ContinueSentinel; context.method = \"throw\", context.arg = new TypeError(\"The iterator does not provide a 'throw' method\"); } return ContinueSentinel; } var record = tryCatch(method, delegate.iterator, context.arg); if (\"throw\" === record.type) return context.method = \"throw\", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, \"return\" !== context.method && (context.method = \"next\", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = \"throw\", context.arg = new TypeError(\"iterator result is not an object\"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = \"normal\", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: \"root\" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if (\"function\" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) { if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; } return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, \"constructor\", { value: GeneratorFunctionPrototype, configurable: !0 }), defineProperty(GeneratorFunctionPrototype, \"constructor\", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, \"GeneratorFunction\"), exports.isGeneratorFunction = function (genFun) { var ctor = \"function\" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || \"GeneratorFunction\" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, \"GeneratorFunction\")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, \"Generator\"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, \"toString\", function () { return \"[object Generator]\"; }), exports.keys = function (val) { var object = Object(val), keys = []; for (var key in object) { keys.push(key); } return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = \"next\", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) { \"t\" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); } }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if (\"throw\" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = \"throw\", record.arg = exception, context.next = loc, caught && (context.method = \"next\", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if (\"root\" === entry.tryLoc) return handle(\"end\"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, \"catchLoc\"), hasFinally = hasOwn.call(entry, \"finallyLoc\"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error(\"try statement without catch or finally\"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, \"finallyLoc\") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && (\"break\" === type || \"continue\" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = \"next\", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if (\"throw\" === record.type) throw record.arg; return \"break\" === record.type || \"continue\" === record.type ? this.next = record.arg : \"return\" === record.type ? (this.rval = this.arg = record.arg, this.method = \"return\", this.next = \"end\") : \"normal\" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, \"catch\": function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if (\"throw\" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error(\"illegal catch attempt\"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, \"next\" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }\nfunction asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }\nfunction _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, \"next\", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, \"throw\", err); } _next(undefined); }); }; }\nvar __signature__ = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal[\"default\"].signature : function (a) {\n return a;\n};\nvar models = __webpack_require__(/*! ../models/motoModels */ \"./server/models/motoModels.js\");\nvar redis = __webpack_require__(/*! redis */ \"redis\");\nvar fetch = function fetch() {\n for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {\n args[_key] = arguments[_key];\n }\n return Promise.resolve(/*! import() */).then(__webpack_require__.t.bind(__webpack_require__, /*! node-fetch */ \"node-fetch\", 23)).then(function (_ref) {\n var fetch = _ref[\"default\"];\n return fetch.apply(void 0, args);\n });\n};\nvar redisClient;\nvar motoController = {};\n_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {\n return _regeneratorRuntime().wrap(function _callee$(_context) {\n while (1) {\n switch (_context.prev = _context.next) {\n case 0:\n redisClient = redis.createClient();\n redisClient.on(\"connect\", function () {\n return console.log('Connected to Redis cache successfully.');\n });\n redisClient.on(\"error\", function (error) {\n return console.error(\"Error : \".concat(error));\n });\n _context.next = 5;\n return redisClient.connect();\n case 5:\n case \"end\":\n return _context.stop();\n }\n }\n }, _callee);\n}))();\nmotoController.addTask = /*#__PURE__*/function () {\n var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(req, res, next) {\n var _req$body, maint, task, cost, moto_id, returnedTask;\n return _regeneratorRuntime().wrap(function _callee2$(_context2) {\n while (1) {\n switch (_context2.prev = _context2.next) {\n case 0:\n _req$body = req.body, maint = _req$body.maint, task = _req$body.task, cost = _req$body.cost, moto_id = _req$body.moto_id;\n if (cost === undefined) cost = 0;\n cost = Number(cost);\n _context2.prev = 3;\n _context2.next = 6;\n return models.Task.create({\n maint: maint,\n task: task,\n cost: cost,\n moto_id: moto_id\n });\n case 6:\n returnedTask = _context2.sent;\n res.locals.task = returnedTask;\n return _context2.abrupt(\"return\", next());\n case 11:\n _context2.prev = 11;\n _context2.t0 = _context2[\"catch\"](3);\n next({\n log: 'error in middleware addTask',\n message: 'error in addTask'\n });\n case 14:\n case \"end\":\n return _context2.stop();\n }\n }\n }, _callee2, null, [[3, 11]]);\n }));\n return function (_x, _x2, _x3) {\n return _ref3.apply(this, arguments);\n };\n}();\nmotoController.getTasks = function (req, res, next) {\n models.Task.find({}).exec().then(function (data) {\n res.locals.tasks = data;\n return next();\n })[\"catch\"](function (err) {\n return next({\n log: 'error in middleware getTasks',\n message: 'error in getTasks'\n });\n });\n};\nmotoController.deleteTask = function (req, res, next) {\n var id = req.body.id;\n models.Task.findOneAndDelete({\n _id: id\n }).exec().then(function (data) {\n res.locals.task = data.task;\n return next();\n })[\"catch\"](function (err) {\n return next({\n log: \"error in middleware deleteTask\",\n message: 'error in middleware deleteTask'\n });\n });\n};\nmotoController.editTask = function (req, res, next) {\n var _req$body2 = req.body,\n id = _req$body2.id,\n done = _req$body2.done,\n newTask = _req$body2.newTask;\n if (newTask !== undefined) {\n var _req$body3 = req.body,\n _id = _req$body3.id,\n _newTask = _req$body3.newTask;\n models.Task.updateOne({\n _id: _id\n }, {\n task: _newTask\n }).exec().then(function (data) {\n return next();\n })[\"catch\"](function (err) {\n return next({\n log: \"error in middleware editTask\",\n message: \"error in middleware editTask\"\n });\n });\n }\n if (done === false || done === true) {\n models.Task.updateOne({\n _id: id\n }, {\n done: done\n }).exec().then(function (data) {\n return next();\n })[\"catch\"](function (err) {\n return next({\n log: \"error in middleware editTask\",\n message: \"error in middleware editTask\"\n });\n });\n }\n};\nmotoController.getBikes = function (req, res, next) {\n models.Moto.find({}).exec().then(function (data) {\n res.locals.bikes = data;\n return next();\n })[\"catch\"](function (err) {\n return next({\n log: 'error in middleware getBikes',\n message: 'error in getMoto'\n });\n });\n};\nmotoController.addBike = /*#__PURE__*/function () {\n var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(req, res, next) {\n var _req$body4, year, make, model, returnedMoto;\n return _regeneratorRuntime().wrap(function _callee3$(_context3) {\n while (1) {\n switch (_context3.prev = _context3.next) {\n case 0:\n _req$body4 = req.body, year = _req$body4.year, make = _req$body4.make, model = _req$body4.model;\n year = Number(year);\n _context3.prev = 2;\n _context3.next = 5;\n return models.Moto.create({\n year: year,\n make: make,\n model: model\n });\n case 5:\n returnedMoto = _context3.sent;\n res.locals.bike = returnedMoto;\n return _context3.abrupt(\"return\", next());\n case 10:\n _context3.prev = 10;\n _context3.t0 = _context3[\"catch\"](2);\n next({\n log: 'error in middleware addBike',\n message: 'error in addBike'\n });\n case 13:\n case \"end\":\n return _context3.stop();\n }\n }\n }, _callee3, null, [[2, 10]]);\n }));\n return function (_x4, _x5, _x6) {\n return _ref4.apply(this, arguments);\n };\n}();\nmotoController.deleteBike = function (req, res, next) {\n var id = req.body.id;\n models.Moto.findOneAndDelete({\n _id: id\n }).exec().then(function (bike) {\n return res.locals.bike = bike;\n })[\"catch\"](function (err) {\n return next({\n log: 'error in middleware deletBike',\n message: 'error in middleware deleteBike'\n });\n });\n models.Task.remove({\n moto_id: id\n }).exec()[\"catch\"](function (err) {\n return next({\n log: 'error in middleware deletBike',\n message: 'error in middleware deleteBike'\n });\n });\n};\nmotoController.getBikeImg = /*#__PURE__*/function () {\n var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(req, res, next) {\n var start, query, value;\n return _regeneratorRuntime().wrap(function _callee4$(_context4) {\n while (1) {\n switch (_context4.prev = _context4.next) {\n case 0:\n start = Date.now();\n query = req.params.query;\n _context4.next = 4;\n return redisClient.get(query);\n case 4:\n value = _context4.sent;\n if (!value) {\n _context4.next = 12;\n break;\n }\n console.log('cache hit');\n res.locals.bikeImg = value;\n console.log('time to return results: ', Date.now() - start);\n return _context4.abrupt(\"return\", next());\n case 12:\n _context4.next = 14;\n return fetch(process.env.GOOGLE_API + req.params.query).then(function (data) {\n return data.json();\n }).then(function (data) {\n if (data) {\n console.log('cache miss');\n redisClient.set(query, data.items[0].pagemap.cse_image[0].src, 'EX', 10, function (err, result) {\n if (err) {\n console.error(err);\n } else console.log('Key set: ', result);\n });\n res.locals.bikeImg = data;\n console.log('time to return results: ', Date.now() - start);\n return next();\n } else return next({\n message: 'ERROR: Google API fetch request failed, likely because you have surpassed your daily limit of queries. Error message',\n log: 'Google API fetch failed'\n });\n })[\"catch\"](function (err) {\n return next({\n message: 'ERROR: Google API fetch request failed, likely because you have surpassed your daily limit of queries. Exact message received by server is: ' + err.message,\n log: 'Google API fetch failed and caught by catch block'\n });\n });\n case 14:\n case \"end\":\n return _context4.stop();\n }\n }\n }, _callee4);\n }));\n return function (_x7, _x8, _x9) {\n return _ref5.apply(this, arguments);\n };\n}();\nmodule.exports = motoController;\n;\n(function () {\n var reactHotLoader = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default : undefined;\n if (!reactHotLoader) {\n return;\n }\n reactHotLoader.register(fetch, \"fetch\", \"/Users/Gahl/Desktop/Codesmith/Week 5/Solo Project/server/controllers/motoController.js\");\n reactHotLoader.register(redisClient, \"redisClient\", \"/Users/Gahl/Desktop/Codesmith/Week 5/Solo Project/server/controllers/motoController.js\");\n reactHotLoader.register(motoController, \"motoController\", \"/Users/Gahl/Desktop/Codesmith/Week 5/Solo Project/server/controllers/motoController.js\");\n})();\n;\n(function () {\n var leaveModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.leaveModule : undefined;\n leaveModule && leaveModule(module);\n})();\n\n//# sourceURL=webpack://solo-project/./server/controllers/motoController.js?");
19 |
20 | /***/ }),
21 |
22 | /***/ "./server/devBundle.js":
23 | /*!*****************************!*\
24 | !*** ./server/devBundle.js ***!
25 | \*****************************/
26 | /***/ ((module, __webpack_exports__, __webpack_require__) => {
27 |
28 | "use strict";
29 | eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"default\": () => (__WEBPACK_DEFAULT_EXPORT__)\n/* harmony export */ });\n/* harmony import */ var webpack__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! webpack */ \"webpack\");\n/* harmony import */ var webpack__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(webpack__WEBPACK_IMPORTED_MODULE_0__);\n/* harmony import */ var webpack_dev_middleware__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! webpack-dev-middleware */ \"webpack-dev-middleware\");\n/* harmony import */ var webpack_dev_middleware__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(webpack_dev_middleware__WEBPACK_IMPORTED_MODULE_1__);\n/* harmony import */ var webpack_hot_middleware__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! webpack-hot-middleware */ \"webpack-hot-middleware\");\n/* harmony import */ var webpack_hot_middleware__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(webpack_hot_middleware__WEBPACK_IMPORTED_MODULE_2__);\n/* harmony import */ var _webpack_config_client_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./../webpack.config.client.js */ \"./webpack.config.client.js\");\n/* harmony import */ var _webpack_config_client_js__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_webpack_config_client_js__WEBPACK_IMPORTED_MODULE_3__);\n/* module decorator */ module = __webpack_require__.hmd(module);\n(function () {\n var enterModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.enterModule : undefined;\n enterModule && enterModule(module);\n})();\nvar __signature__ = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal[\"default\"].signature : function (a) {\n return a;\n};\n\n\n\n\nvar compile = function compile(app) {\n if (true) {\n var compiler = webpack__WEBPACK_IMPORTED_MODULE_0___default()((_webpack_config_client_js__WEBPACK_IMPORTED_MODULE_3___default()));\n var middleware = webpack_dev_middleware__WEBPACK_IMPORTED_MODULE_1___default()(compiler, {\n publicPath: (_webpack_config_client_js__WEBPACK_IMPORTED_MODULE_3___default().output.publicPath)\n });\n app.use(middleware);\n app.use(webpack_hot_middleware__WEBPACK_IMPORTED_MODULE_2___default()(compiler));\n }\n};\nvar _default = {\n compile: compile\n};\n/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (_default);\n;\n(function () {\n var reactHotLoader = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default : undefined;\n if (!reactHotLoader) {\n return;\n }\n reactHotLoader.register(compile, \"compile\", \"/Users/Gahl/Desktop/Codesmith/Week 5/Solo Project/server/devBundle.js\");\n reactHotLoader.register(_default, \"default\", \"/Users/Gahl/Desktop/Codesmith/Week 5/Solo Project/server/devBundle.js\");\n})();\n;\n(function () {\n var leaveModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.leaveModule : undefined;\n leaveModule && leaveModule(module);\n})();\n\n//# sourceURL=webpack://solo-project/./server/devBundle.js?");
30 |
31 | /***/ }),
32 |
33 | /***/ "./server/models/motoModels.js":
34 | /*!*************************************!*\
35 | !*** ./server/models/motoModels.js ***!
36 | \*************************************/
37 | /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
38 |
39 | eval("/* module decorator */ module = __webpack_require__.nmd(module);\n(function () {\n var enterModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.enterModule : undefined;\n enterModule && enterModule(module);\n})();\nvar __signature__ = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal[\"default\"].signature : function (a) {\n return a;\n};\nvar mongoose = __webpack_require__(/*! mongoose */ \"mongoose\");\n(__webpack_require__(/*! dotenv */ \"dotenv\").config)();\n\n// let uri = process.env.MONGO_URI\n\nmongoose.connect(process.env.MONGO_URI, {\n // options for the connect method to parse the URI\n useNewUrlParser: true,\n useUnifiedTopology: true,\n // sets the name of the DB that our collections are part of\n dbName: 'moto'\n}).then(function () {\n return console.log('Connected to Mongo DB.');\n})[\"catch\"](function (err) {\n return console.log(err);\n});\nvar Schema = mongoose.Schema;\nvar taskSchema = new Schema({\n done: {\n type: Boolean,\n \"default\": false\n },\n maint: {\n type: Boolean,\n required: true\n },\n task: {\n type: String,\n required: true\n },\n cost: Number,\n moto_id: {\n type: Schema.Types.ObjectId,\n ref: 'moto'\n }\n});\nvar Task = mongoose.model('Task', taskSchema);\nvar motoSchema = new Schema({\n year: Number,\n make: String,\n model: String\n});\nvar Moto = mongoose.model('Moto', motoSchema);\nmodule.exports = {\n Task: Task,\n Moto: Moto\n};\n;\n(function () {\n var reactHotLoader = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default : undefined;\n if (!reactHotLoader) {\n return;\n }\n reactHotLoader.register(Schema, \"Schema\", \"/Users/Gahl/Desktop/Codesmith/Week 5/Solo Project/server/models/motoModels.js\");\n reactHotLoader.register(taskSchema, \"taskSchema\", \"/Users/Gahl/Desktop/Codesmith/Week 5/Solo Project/server/models/motoModels.js\");\n reactHotLoader.register(Task, \"Task\", \"/Users/Gahl/Desktop/Codesmith/Week 5/Solo Project/server/models/motoModels.js\");\n reactHotLoader.register(motoSchema, \"motoSchema\", \"/Users/Gahl/Desktop/Codesmith/Week 5/Solo Project/server/models/motoModels.js\");\n reactHotLoader.register(Moto, \"Moto\", \"/Users/Gahl/Desktop/Codesmith/Week 5/Solo Project/server/models/motoModels.js\");\n})();\n;\n(function () {\n var leaveModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.leaveModule : undefined;\n leaveModule && leaveModule(module);\n})();\n\n//# sourceURL=webpack://solo-project/./server/models/motoModels.js?");
40 |
41 | /***/ }),
42 |
43 | /***/ "./server/routes/api.js":
44 | /*!******************************!*\
45 | !*** ./server/routes/api.js ***!
46 | \******************************/
47 | /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
48 |
49 | eval("/* module decorator */ module = __webpack_require__.nmd(module);\n(function () {\n var enterModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.enterModule : undefined;\n enterModule && enterModule(module);\n})();\nvar __signature__ = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal[\"default\"].signature : function (a) {\n return a;\n};\nvar express = __webpack_require__(/*! express */ \"express\");\nvar motoController = __webpack_require__(/*! ../controllers/motoController */ \"./server/controllers/motoController.js\");\nvar router = express.Router();\nrouter.get('/tasks', motoController.getTasks, function (req, res) {\n return res.status(200).json(res.locals);\n});\nrouter.get('/bike', motoController.getBikes, function (req, res) {\n return res.status(200).json(res.locals);\n});\nrouter.get('/', motoController.getTasks, motoController.getBikes, function (req, res) {\n return res.status(200).json(res.locals);\n});\nrouter.post('/', motoController.addTask, function (req, res) {\n return res.status(200).json(\"successfully added \".concat(res.locals.task));\n});\nrouter[\"delete\"]('/', motoController.deleteTask, function (req, res) {\n return res.status(200).json(\"Successfully deleted \".concat(res.locals.task));\n});\nrouter.patch('/', motoController.editTask, function (req, res) {\n return res.status(200).json('Successfully updated task');\n});\nrouter.post('/bike', motoController.addBike, function (req, res) {\n return res.status(200).json(res.locals.bike);\n});\nrouter[\"delete\"]('/bike', motoController.deleteBike, function (req, res) {\n return res.status(200).json(\"Successfully deleted \".concat(res.locals.bike));\n});\nrouter.get('/all', motoController.getTasks, motoController.getBikes, function (req, res) {\n return res.status(200).json(res.locals);\n});\nrouter.get('/bikeImg/:query', motoController.getBikeImg, function (req, res) {\n return res.status(200).json(res.locals.bikeImg);\n});\nmodule.exports = router;\n;\n(function () {\n var reactHotLoader = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default : undefined;\n if (!reactHotLoader) {\n return;\n }\n reactHotLoader.register(router, \"router\", \"/Users/Gahl/Desktop/Codesmith/Week 5/Solo Project/server/routes/api.js\");\n})();\n;\n(function () {\n var leaveModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.leaveModule : undefined;\n leaveModule && leaveModule(module);\n})();\n\n//# sourceURL=webpack://solo-project/./server/routes/api.js?");
50 |
51 | /***/ }),
52 |
53 | /***/ "./server/server.js":
54 | /*!**************************!*\
55 | !*** ./server/server.js ***!
56 | \**************************/
57 | /***/ ((module, __webpack_exports__, __webpack_require__) => {
58 |
59 | "use strict";
60 | eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var express__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! express */ \"express\");\n/* harmony import */ var express__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(express__WEBPACK_IMPORTED_MODULE_0__);\n/* harmony import */ var _devBundle__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./devBundle */ \"./server/devBundle.js\");\n/* harmony import */ var path__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! path */ \"path\");\n/* harmony import */ var path__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(path__WEBPACK_IMPORTED_MODULE_2__);\n/* harmony import */ var _template__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./../template */ \"./template.js\");\n/* harmony import */ var mongoose__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! mongoose */ \"mongoose\");\n/* harmony import */ var mongoose__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(mongoose__WEBPACK_IMPORTED_MODULE_4__);\n/* module decorator */ module = __webpack_require__.hmd(module);\n(function () {\n var enterModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.enterModule : undefined;\n enterModule && enterModule(module);\n})();\nvar __signature__ = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal[\"default\"].signature : function (a) {\n return a;\n};\n\n\n\n\n\nvar app = express__WEBPACK_IMPORTED_MODULE_0___default()();\n_devBundle__WEBPACK_IMPORTED_MODULE_1__[\"default\"].compile(app);\nvar CURRENT_WORKING_DIR = process.cwd();\nvar apiRouter = __webpack_require__(/*! ./routes/api */ \"./server/routes/api.js\");\n(__webpack_require__(/*! dotenv */ \"dotenv\").config)();\nvar models = __webpack_require__(/*! ./models/motoModels */ \"./server/models/motoModels.js\");\nvar port = process.env.PORT || 3000;\n\n// handles parsing request body\napp.use(express__WEBPACK_IMPORTED_MODULE_0___default().json());\napp.use(express__WEBPACK_IMPORTED_MODULE_0___default().urlencoded({\n extended: true\n}));\n\n// serves static bundle file\napp.use('/dist', express__WEBPACK_IMPORTED_MODULE_0___default()[\"static\"](path__WEBPACK_IMPORTED_MODULE_2___default().join(CURRENT_WORKING_DIR, 'dist')));\n\n//routes requests to api\napp.use('/api', apiRouter);\napp.get('/', function (req, res) {\n res.status(200).send((0,_template__WEBPACK_IMPORTED_MODULE_3__[\"default\"])());\n});\napp.use(function (req, res) {\n return res.status(404).send('Error 404: This page does not exist');\n});\n\n// Global Error Handler\napp.use(function (err, req, res, next) {\n var defaultErr = {\n log: 'Express error handler caught unknown middleware error',\n status: 500,\n message: {\n err: 'An error occurred'\n }\n };\n var errorObj = Object.assign({}, defaultErr, err);\n console.log(errorObj.log);\n return res.status(errorObj.status).json(errorObj.message);\n});\napp.listen(port, function (err) {\n if (err) {\n console.log(err);\n }\n console.info('Server started on port %s.', port);\n});\n;\n(function () {\n var reactHotLoader = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default : undefined;\n if (!reactHotLoader) {\n return;\n }\n reactHotLoader.register(app, \"app\", \"/Users/Gahl/Desktop/Codesmith/Week 5/Solo Project/server/server.js\");\n reactHotLoader.register(CURRENT_WORKING_DIR, \"CURRENT_WORKING_DIR\", \"/Users/Gahl/Desktop/Codesmith/Week 5/Solo Project/server/server.js\");\n reactHotLoader.register(port, \"port\", \"/Users/Gahl/Desktop/Codesmith/Week 5/Solo Project/server/server.js\");\n})();\n;\n(function () {\n var leaveModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.leaveModule : undefined;\n leaveModule && leaveModule(module);\n})();\n\n//# sourceURL=webpack://solo-project/./server/server.js?");
61 |
62 | /***/ }),
63 |
64 | /***/ "./template.js":
65 | /*!*********************!*\
66 | !*** ./template.js ***!
67 | \*********************/
68 | /***/ ((module, __webpack_exports__, __webpack_require__) => {
69 |
70 | "use strict";
71 | eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"default\": () => (__WEBPACK_DEFAULT_EXPORT__)\n/* harmony export */ });\n/* module decorator */ module = __webpack_require__.hmd(module);\n(function () {\n var enterModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.enterModule : undefined;\n enterModule && enterModule(module);\n})();\nvar __signature__ = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal[\"default\"].signature : function (a) {\n return a;\n};\nvar _default = function _default() {\n return \"\\n \\n \\n \\n Solo\\n \\n \\n \\n \\n \\n \";\n};\n/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (_default);\n;\n(function () {\n var reactHotLoader = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default : undefined;\n if (!reactHotLoader) {\n return;\n }\n reactHotLoader.register(_default, \"default\", \"/Users/Gahl/Desktop/Codesmith/Week 5/Solo Project/template.js\");\n})();\n;\n(function () {\n var leaveModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.leaveModule : undefined;\n leaveModule && leaveModule(module);\n})();\n\n//# sourceURL=webpack://solo-project/./template.js?");
72 |
73 | /***/ }),
74 |
75 | /***/ "./webpack.config.client.js":
76 | /*!**********************************!*\
77 | !*** ./webpack.config.client.js ***!
78 | \**********************************/
79 | /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
80 |
81 | eval("/* module decorator */ module = __webpack_require__.nmd(module);\n(function () {\n var enterModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.enterModule : undefined;\n enterModule && enterModule(module);\n})();\nvar __signature__ = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal[\"default\"].signature : function (a) {\n return a;\n};\nvar path = __webpack_require__(/*! path */ \"path\");\nvar webpack = __webpack_require__(/*! webpack */ \"webpack\");\n//const HtmlWebpackPlugin = require('html-webpack-plugin');\nvar CURRENT_WORKING_DIR = process.cwd();\nvar config = {\n name: 'browser',\n mode: 'development',\n devtool: 'eval-source-map',\n entry: ['webpack-hot-middleware/client?reload=true', path.join(CURRENT_WORKING_DIR, '/client/index.js')],\n output: {\n path: path.join(CURRENT_WORKING_DIR, '/dist'),\n filename: 'bundle.js',\n publicPath: '/dist/'\n },\n module: {\n rules: [{\n test: /\\.jsx?$/,\n exclude: /node_modules/,\n use: {\n loader: 'babel-loader',\n options: {\n presets: ['@babel/preset-env', ['@babel/preset-react', {\n \"runtime\": \"automatic\"\n }]]\n }\n }\n }, {\n test: /\\.css$/i,\n use: [\"style-loader\", \"css-loader\"]\n }, {\n test: /\\.s[ac]ss$/i,\n use: [\"style-loader\", \"css-loader\", \"sass-loader\"]\n }]\n },\n plugins: [new webpack.HotModuleReplacementPlugin(), new webpack.NoEmitOnErrorsPlugin()],\n resolve: {\n alias: {\n 'react-dom': '@hot-loader/react-dom'\n },\n extensions: ['', '.js', '.jsx']\n }\n};\nmodule.exports = config;\n;\n(function () {\n var reactHotLoader = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default : undefined;\n if (!reactHotLoader) {\n return;\n }\n reactHotLoader.register(CURRENT_WORKING_DIR, \"CURRENT_WORKING_DIR\", \"/Users/Gahl/Desktop/Codesmith/Week 5/Solo Project/webpack.config.client.js\");\n reactHotLoader.register(config, \"config\", \"/Users/Gahl/Desktop/Codesmith/Week 5/Solo Project/webpack.config.client.js\");\n})();\n;\n(function () {\n var leaveModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.leaveModule : undefined;\n leaveModule && leaveModule(module);\n})();\n\n//# sourceURL=webpack://solo-project/./webpack.config.client.js?");
82 |
83 | /***/ }),
84 |
85 | /***/ "dotenv":
86 | /*!*************************!*\
87 | !*** external "dotenv" ***!
88 | \*************************/
89 | /***/ ((module) => {
90 |
91 | "use strict";
92 | module.exports = require("dotenv");
93 |
94 | /***/ }),
95 |
96 | /***/ "express":
97 | /*!**************************!*\
98 | !*** external "express" ***!
99 | \**************************/
100 | /***/ ((module) => {
101 |
102 | "use strict";
103 | module.exports = require("express");
104 |
105 | /***/ }),
106 |
107 | /***/ "mongoose":
108 | /*!***************************!*\
109 | !*** external "mongoose" ***!
110 | \***************************/
111 | /***/ ((module) => {
112 |
113 | "use strict";
114 | module.exports = require("mongoose");
115 |
116 | /***/ }),
117 |
118 | /***/ "node-fetch":
119 | /*!*****************************!*\
120 | !*** external "node-fetch" ***!
121 | \*****************************/
122 | /***/ ((module) => {
123 |
124 | "use strict";
125 | module.exports = require("node-fetch");
126 |
127 | /***/ }),
128 |
129 | /***/ "redis":
130 | /*!************************!*\
131 | !*** external "redis" ***!
132 | \************************/
133 | /***/ ((module) => {
134 |
135 | "use strict";
136 | module.exports = require("redis");
137 |
138 | /***/ }),
139 |
140 | /***/ "webpack":
141 | /*!**************************!*\
142 | !*** external "webpack" ***!
143 | \**************************/
144 | /***/ ((module) => {
145 |
146 | "use strict";
147 | module.exports = require("webpack");
148 |
149 | /***/ }),
150 |
151 | /***/ "webpack-dev-middleware":
152 | /*!*****************************************!*\
153 | !*** external "webpack-dev-middleware" ***!
154 | \*****************************************/
155 | /***/ ((module) => {
156 |
157 | "use strict";
158 | module.exports = require("webpack-dev-middleware");
159 |
160 | /***/ }),
161 |
162 | /***/ "webpack-hot-middleware":
163 | /*!*****************************************!*\
164 | !*** external "webpack-hot-middleware" ***!
165 | \*****************************************/
166 | /***/ ((module) => {
167 |
168 | "use strict";
169 | module.exports = require("webpack-hot-middleware");
170 |
171 | /***/ }),
172 |
173 | /***/ "path":
174 | /*!***********************!*\
175 | !*** external "path" ***!
176 | \***********************/
177 | /***/ ((module) => {
178 |
179 | "use strict";
180 | module.exports = require("path");
181 |
182 | /***/ })
183 |
184 | /******/ });
185 | /************************************************************************/
186 | /******/ // The module cache
187 | /******/ var __webpack_module_cache__ = {};
188 | /******/
189 | /******/ // The require function
190 | /******/ function __webpack_require__(moduleId) {
191 | /******/ // Check if module is in cache
192 | /******/ var cachedModule = __webpack_module_cache__[moduleId];
193 | /******/ if (cachedModule !== undefined) {
194 | /******/ return cachedModule.exports;
195 | /******/ }
196 | /******/ // Create a new module (and put it into the cache)
197 | /******/ var module = __webpack_module_cache__[moduleId] = {
198 | /******/ id: moduleId,
199 | /******/ loaded: false,
200 | /******/ exports: {}
201 | /******/ };
202 | /******/
203 | /******/ // Execute the module function
204 | /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
205 | /******/
206 | /******/ // Flag the module as loaded
207 | /******/ module.loaded = true;
208 | /******/
209 | /******/ // Return the exports of the module
210 | /******/ return module.exports;
211 | /******/ }
212 | /******/
213 | /************************************************************************/
214 | /******/ /* webpack/runtime/compat get default export */
215 | /******/ (() => {
216 | /******/ // getDefaultExport function for compatibility with non-harmony modules
217 | /******/ __webpack_require__.n = (module) => {
218 | /******/ var getter = module && module.__esModule ?
219 | /******/ () => (module['default']) :
220 | /******/ () => (module);
221 | /******/ __webpack_require__.d(getter, { a: getter });
222 | /******/ return getter;
223 | /******/ };
224 | /******/ })();
225 | /******/
226 | /******/ /* webpack/runtime/create fake namespace object */
227 | /******/ (() => {
228 | /******/ var getProto = Object.getPrototypeOf ? (obj) => (Object.getPrototypeOf(obj)) : (obj) => (obj.__proto__);
229 | /******/ var leafPrototypes;
230 | /******/ // create a fake namespace object
231 | /******/ // mode & 1: value is a module id, require it
232 | /******/ // mode & 2: merge all properties of value into the ns
233 | /******/ // mode & 4: return value when already ns object
234 | /******/ // mode & 16: return value when it's Promise-like
235 | /******/ // mode & 8|1: behave like require
236 | /******/ __webpack_require__.t = function(value, mode) {
237 | /******/ if(mode & 1) value = this(value);
238 | /******/ if(mode & 8) return value;
239 | /******/ if(typeof value === 'object' && value) {
240 | /******/ if((mode & 4) && value.__esModule) return value;
241 | /******/ if((mode & 16) && typeof value.then === 'function') return value;
242 | /******/ }
243 | /******/ var ns = Object.create(null);
244 | /******/ __webpack_require__.r(ns);
245 | /******/ var def = {};
246 | /******/ leafPrototypes = leafPrototypes || [null, getProto({}), getProto([]), getProto(getProto)];
247 | /******/ for(var current = mode & 2 && value; typeof current == 'object' && !~leafPrototypes.indexOf(current); current = getProto(current)) {
248 | /******/ Object.getOwnPropertyNames(current).forEach((key) => (def[key] = () => (value[key])));
249 | /******/ }
250 | /******/ def['default'] = () => (value);
251 | /******/ __webpack_require__.d(ns, def);
252 | /******/ return ns;
253 | /******/ };
254 | /******/ })();
255 | /******/
256 | /******/ /* webpack/runtime/define property getters */
257 | /******/ (() => {
258 | /******/ // define getter functions for harmony exports
259 | /******/ __webpack_require__.d = (exports, definition) => {
260 | /******/ for(var key in definition) {
261 | /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
262 | /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
263 | /******/ }
264 | /******/ }
265 | /******/ };
266 | /******/ })();
267 | /******/
268 | /******/ /* webpack/runtime/harmony module decorator */
269 | /******/ (() => {
270 | /******/ __webpack_require__.hmd = (module) => {
271 | /******/ module = Object.create(module);
272 | /******/ if (!module.children) module.children = [];
273 | /******/ Object.defineProperty(module, 'exports', {
274 | /******/ enumerable: true,
275 | /******/ set: () => {
276 | /******/ throw new Error('ES Modules may not assign module.exports or exports.*, Use ESM export syntax, instead: ' + module.id);
277 | /******/ }
278 | /******/ });
279 | /******/ return module;
280 | /******/ };
281 | /******/ })();
282 | /******/
283 | /******/ /* webpack/runtime/hasOwnProperty shorthand */
284 | /******/ (() => {
285 | /******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
286 | /******/ })();
287 | /******/
288 | /******/ /* webpack/runtime/make namespace object */
289 | /******/ (() => {
290 | /******/ // define __esModule on exports
291 | /******/ __webpack_require__.r = (exports) => {
292 | /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
293 | /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
294 | /******/ }
295 | /******/ Object.defineProperty(exports, '__esModule', { value: true });
296 | /******/ };
297 | /******/ })();
298 | /******/
299 | /******/ /* webpack/runtime/node module decorator */
300 | /******/ (() => {
301 | /******/ __webpack_require__.nmd = (module) => {
302 | /******/ module.paths = [];
303 | /******/ if (!module.children) module.children = [];
304 | /******/ return module;
305 | /******/ };
306 | /******/ })();
307 | /******/
308 | /************************************************************************/
309 | /******/
310 | /******/ // startup
311 | /******/ // Load entry module and return exports
312 | /******/ // This entry module is referenced by other modules so it can't be inlined
313 | /******/ var __webpack_exports__ = __webpack_require__("./server/server.js");
314 | /******/ module.exports = __webpack_exports__;
315 | /******/
316 | /******/ })()
317 | ;
--------------------------------------------------------------------------------