From b67f11f89aab1c024f2c9c6fbcc620f4ea9cd644 Mon Sep 17 00:00:00 2001 From: Carlos Date: Tue, 10 Mar 2020 00:17:13 -0500 Subject: [PATCH] debugging mode still --- middleware/validate.js | 4 +--- modules/auth-model/index.js | 2 +- modules/user-model/index.js | 2 +- routers/auth-router/index.js | 5 ++-- routers/users-router/index.js | 45 +++++++++++++++++++++-------------- server/api.js | 10 ++++---- 6 files changed, 37 insertions(+), 31 deletions(-) diff --git a/middleware/validate.js b/middleware/validate.js index 3c5c0df..6b8a955 100644 --- a/middleware/validate.js +++ b/middleware/validate.js @@ -9,6 +9,4 @@ function validateMiddlware(req, res, next) { } } -module.exports = { - validateMiddlware -}; +module.exports = { validateMiddlware }; diff --git a/modules/auth-model/index.js b/modules/auth-model/index.js index 51932f4..4d579f3 100644 --- a/modules/auth-model/index.js +++ b/modules/auth-model/index.js @@ -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) { diff --git a/modules/user-model/index.js b/modules/user-model/index.js index 2eab5e2..f7d027d 100644 --- a/modules/user-model/index.js +++ b/modules/user-model/index.js @@ -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"); diff --git a/routers/auth-router/index.js b/routers/auth-router/index.js index e4b5c49..887d0e5 100644 --- a/routers/auth-router/index.js +++ b/routers/auth-router/index.js @@ -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) => { @@ -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); diff --git a/routers/users-router/index.js b/routers/users-router/index.js index e20b0f9..f65f2db 100644 --- a/routers/users-router/index.js +++ b/routers/users-router/index.js @@ -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; diff --git a/server/api.js b/server/api.js index 5bd98fe..4b69e04 100644 --- a/server/api.js +++ b/server/api.js @@ -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"); @@ -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);