Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions config/connection.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
const Sequelize = require('sequelize');

require('dotenv').config()

module.exports = new Sequelize(process.env.DB_NAME, process.env.DB_USER, process.env.DB_PASSWORD, {
const sequelize = new Sequelize(process.env.DB_NAME, process.env.DB_USER, process.env.DB_PASSWORD, {
host: 'localhost',
dialect: 'mysql',
port: 3306
})
})

module.exports = sequelize;
6 changes: 0 additions & 6 deletions controllers/api/user-routes

This file was deleted.

84 changes: 84 additions & 0 deletions controllers/api/user-routes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
const router = require('express').Router()
const { User, Monthly, Yearly, Single, Income } = require('../../models')

// GET /api/users
router.get("/", (req, res) => {
// Finds all the info for Users on the table.
User.findAll({
// Prevents the password from being pulled
attributes: { exclude: ["password"] },
})
// Sends the info back to the client
.then((dbUserData) => res.json(dbUserData))
// If there is an error, send the error back to the client
.catch((err) => {
console.log(err);
res.status(500).json(err);
});
});

// GET /api/users/1
router.get("/:id", (req, res) => {
// Finds a specified user
User.findOne({
// Prevents the password from being pulled
attributes: { exclude: ["password"] },
})
.then((dbUserData) => {
if (!dbUserData) {
res.status(404).json({ message: "No user found with this id" });
return;
}
res.json(dbUserData);
})
.catch((err) => {
console.log(err);
res.status(500).json(err);
});
});

// POST /api/users
router.post("/", (req, res) => {
// should expect {usernam: 'value', email: 'value@value.com', password: 'value'}
console.log(req.body);
// Sets the information that must be put in
User.create({
// requires the username, email, and password
username: req.body.username,
email: req.body.email,
password: req.body.password,
}).then(dbUserData => {
console.log(dbUserData);
res.json(dbUserData);
}) .catch(err => {
console.log(err);
res.status(500).json(err);
});
});

// DELETE /api/users/1
// Deletes the information stored in user at this id
router.delete("/:id", (req, res) => {
// Sets the table to be deleted
User.destroy({
where: {
// Specifies the exact location where it will delete data from
id: req.params.id,
},
})
.then((dbUserData) => {
if (!dbUserData) {
// Will send a message saying it cannot find the user
res.status(404).json({ message: "No user found with this id" });
return;
}
res.json(dbUserData);
})
// Returns a response should there be an error
.catch((err) => {
console.log(err);
res.status(500).json(err);
});
});

module.exports = router
Binary file added frameworks/Dashboard.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added frameworks/Homepage.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion models/User.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,4 @@ User.init(
}
);

module.export = User;
module.exports = User;
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"description": "",
"main": "server.js",
"scripts": {
"start": "node server.js"
"start": "node server.js",
"seed": "node seeds/index.js"
},
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion server.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const sequelize = require('./config/connection')
const routes = require('./controllers')

const app = express()
const PORT = process.env.PORT || 3001
const PORT = process.env.PORT || 3006

app.use(express.json());
app.use(express.urlencoded({ extended: true }));
Expand Down