-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from ShahandFahad/usermgmt
Usermgmt
- Loading branch information
Showing
7 changed files
with
79 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,23 @@ | ||
const express = require("express"); | ||
const app = express(); | ||
|
||
app.use(express.json()); // json parser | ||
app.use(express.json()); // json parser: req handler middleware | ||
|
||
app.get("/", (req, res) => { | ||
res.status(200).send("User Management Serivice"); | ||
// Run in development env | ||
if (process.env.NODE_ENV === "development") { | ||
const morgan = require("morgan"); | ||
app.use(morgan("dev")); | ||
} | ||
|
||
// User routes | ||
const userRoutes = require("./src/routes/userRoutes"); | ||
|
||
// Routes | ||
app.use("/api/v1/user", userRoutes); | ||
|
||
// Handle Non-Existing Routes: Return 404 | ||
app.all("*", (req, res) => { | ||
res.status(404).json({ staus: "Failed", message: "Not Found!" }); | ||
}); | ||
|
||
module.exports = app; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,12 @@ | ||
// Load Environment Variables: At the top of your app.js file | ||
require("dotenv").config({ path: `${__dirname}/env/.env.development` }); | ||
// import app.js here | ||
const app = require("../app"); | ||
|
||
// Start server | ||
const PORT = 8001; | ||
app.listen(PORT, () => { | ||
const port = process.env.PORT || 8000; | ||
app.listen(port, () => { | ||
console.log( | ||
`User Management: Server is running on: http://localhost:${PORT}` | ||
`User Management: Server is running on: http://localhost:${port}` | ||
); | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// GET: Get all users from DB | ||
exports.getAllUsers = (req, res) => { | ||
res.status(200).json({ status: "Success", message: "Get All Users" }); | ||
}; | ||
|
||
// POST: Post | Add new user to DB | ||
exports.createUser = (req, res) => { | ||
res.status(200).json({ status: "Success", message: "New User Added" }); | ||
}; | ||
|
||
// GET: Get user by ID | ||
exports.getUser = (req, res) => { | ||
res.status(200).json({ status: "Success", message: "Get User by ID" }); | ||
}; | ||
|
||
// UPDATE: Update user details | ||
exports.updateUser = (req, res) => { | ||
res.status(200).json({ status: "Success", message: "User Updated" }); | ||
}; | ||
|
||
// DELETE: Delete user | ||
exports.deleteUser = (req, res) => { | ||
res.status(200).json({ status: "Success", message: "User Deleted" }); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
const express = require("express"); | ||
const router = express.Router(); | ||
|
||
// Get user route controller | ||
const userController = require("../controllers/userController"); | ||
|
||
// Router setup | ||
router | ||
.route("/") | ||
.get(userController.getAllUsers) | ||
.post(userController.createUser); | ||
|
||
router | ||
.route("/:id") | ||
.get(userController.getUser) | ||
.patch(userController.updateUser) | ||
.delete(userController.deleteUser); | ||
|
||
module.exports = router; |