Skip to content

Commit

Permalink
debugging mode still
Browse files Browse the repository at this point in the history
  • Loading branch information
Carlos committed Mar 10, 2020
1 parent 282c14d commit b67f11f
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 31 deletions.
4 changes: 1 addition & 3 deletions middleware/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,4 @@ function validateMiddlware(req, res, next) {
}
}

module.exports = {
validateMiddlware
};
module.exports = { validateMiddlware };
2 changes: 1 addition & 1 deletion modules/auth-model/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const db = require("../../database/dbConfig");

async function userAccount(username) {
const user = await db("blogdb")
const user = await db("users")
.where({ username })
.first();
if (user) {
Expand Down
2 changes: 1 addition & 1 deletion modules/user-model/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const bcrypt = require("bcryptjs");
const db = requrie("../../database/dbConfig");
const db = require("../../database/dbConfig");

function find() {
return db("users").select("id", "firstName", "lastName", "username");
Expand Down
5 changes: 2 additions & 3 deletions routers/auth-router/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ const express = require("express");
const bcrypt = require("bcryptjs");
// HELPER MODULES
const usersModel = require("../../modules/user-model");
const authenticationModel = require("../../modules/auth-model");
const authModel = require("../../modules/auth-model");
// EXPRESS MIDDLEWEAR
const { validateMiddleware } = require("../../middleware/validate");
const generateToken = require("../../middleware/generateToken");

const router = express.Router();
// CREATE NEW USER POST
router.post("/register", async (req, res, next) => {
Expand All @@ -22,7 +21,7 @@ router.post("/register", async (req, res, next) => {
router.post("/login", validateMiddleware, async (req, res, next) => {
try {
let { username, password } = req.body;
const user = await authenticationModel.userAccount(username);
const user = await authModel.userAccount(username);
const passwordValid = await bcrypt.compare(password, user.password);
// if user and password are good then you get token
console.log(passwordValid, user);
Expand Down
45 changes: 27 additions & 18 deletions routers/users-router/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,32 @@ router.post("/", async (req, res, next) => {
console.log(newUser);
});
// EDIT USER PUT
router.put("/:id", async (req, res, next) => {
try {
const [id] = await db("users")
.update(req.params.id, re.body)
.then(user => {
if (user) {
return res.status(200).json(user);
} else {
return res.status(404).json({ message: "couldn't find user" });
}
});
} catch (err) {
return res
.status(404)
.json({ message: "error on put/edit request muchacho" });
}
});
// router.put("/:id", async (req, res, next) => {
// try {
// const [id] = await db("users")
// .update(req.params.id, re.body)
// .then(user => {
// if (user) {
// return res.status(200).json(user);
// } else {
// return res.status(404).json({ message: "couldn't find user" });
// }
// });
// } catch (err) {
// return res
// .status(404)
// .json({ message: "error on put/edit request muchacho" });
// }
// });

//DELETE USER
// router.delete("/:id", async (req, res, next) => {
// try {
// await usersModel.remove(req.params.id);
// return res.status(204).json({ message: "user deleted/removed" });
// } catch (err) {
// next(err);
// }
// });

//delete user
module.exports = router;
10 changes: 5 additions & 5 deletions server/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ const cors = require("cors");

const apiRouter = require("../routers/api-router");
// AUTH ROUTER
// const authRouter = require("../routers/auth-router");
// // USER ROUTER
// const usersRouter = require("../routers/users-router");
const authRouter = require("../routers/auth-router");
// USER ROUTER
const usersRouter = require("../routers/users-router");
// // BLOG ROUTER
// const blogRouter = require("../routers/blog-router");

Expand All @@ -28,9 +28,9 @@ server.use("/", apiRouter);
// API ROUTE
server.use("/api", apiRouter);
// AUTH ROUTE
// server.use("/api/auth", authRouter);
server.use("/api/auth", authRouter);
// // USER ROUTE
// server.use("/api/user", usersRouter);
server.use("/api/users", usersRouter);
// // BLOG ROUTE
// server.use("/api/blog", blogRouter);

Expand Down

0 comments on commit b67f11f

Please sign in to comment.