-
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.
Started documentation for end points
- Loading branch information
1 parent
2cc81c0
commit 763d215
Showing
5 changed files
with
106 additions
and
94 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 +1,5 @@ | ||
# Back-end | ||
# Farm Fresh API | ||
|
||
--- | ||
|
||
[Documentation](https://web.postman.co/collections/11725136-f9e17211-9122-41f4-b758-902d6d1387b7?version=latest&workspace=faa2959a-ee89-44cb-8769-476dad3a658d) |
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,14 +1,14 @@ | ||
const jwt = require('jsonwebtoken') | ||
const jwt_secrets = require('../config/secrets.js') | ||
const jwt = require("jsonwebtoken"); | ||
const jwt_secrets = require("../config/secrets.js"); | ||
|
||
module.exports = (req, res, next) => { | ||
let token = req.headers.authorization | ||
let token = req.headers.authorization; | ||
if (token) { | ||
jwt.verify(token, jwt_secrets.jwtSecret, (err, decodedToken) => { | ||
req.decodedJwt = decodedToken | ||
next() | ||
}) | ||
req.decodedJwt = decodedToken; | ||
next(); | ||
}); | ||
} else { | ||
res.status(400).json({ errorMessage: "You must be logged in" }) | ||
res.status(400).json({ errorMessage: "You must be logged in" }); | ||
} | ||
} | ||
}; |
Binary file not shown.
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,44 +1,51 @@ | ||
const router = require('express').Router(); | ||
const router = require("express").Router(); | ||
|
||
const Users = require('../users/usersModel'); | ||
const Users = require("../users/usersModel"); | ||
|
||
router.get('/', async (req, res) => { | ||
const users = await Users.find() | ||
res.status(200).json(users) | ||
}) | ||
router.get("/", async (req, res) => { | ||
const users = await Users.find(); | ||
res.status(200).json(users); | ||
}); | ||
|
||
router.get('/:id', async (req, res) => { | ||
const id = req.params.id | ||
let user = await Users.findById(id) | ||
const profile = await Users.findProfile(id) | ||
const location = await Users.findLocation(id) | ||
res.status(200).json({ ...user, profile: profile, location: location }) | ||
}) | ||
router.get("/:id", async (req, res) => { | ||
const id = req.params.id; | ||
console.log(id); | ||
let user = await Users.findById(id); | ||
const profile = await Users.findProfile(id); | ||
const location = await Users.findLocation(id); | ||
res.status(200).json({ | ||
...user, | ||
profile: profile ? profile : {}, | ||
location: location ? location : {}, | ||
}); | ||
}); | ||
|
||
router.delete('/:id', async (req, res) => { | ||
const id = req.params.id | ||
const user = await Users.findById(id) | ||
await Users.del(id) | ||
res.status(200).json(({ message: `User with the ID of ${user.id} has been removed` })) | ||
}) | ||
router.delete("/:id", async (req, res) => { | ||
const id = req.params.id; | ||
const user = await Users.findById(id); | ||
await Users.del(id); | ||
res | ||
.status(200) | ||
.json({ message: `User with the ID of ${user.id} has been removed` }); | ||
}); | ||
|
||
router.get('/:id/cart', async (req, res) => { | ||
const id = req.params.id | ||
const user = await Users.findById(id) | ||
const cart = await Users.findCartById(id) | ||
res.status(200).json({ userId: user.id, cart: cart }) | ||
}) | ||
router.get("/:id/cart", async (req, res) => { | ||
const id = req.params.id; | ||
const user = await Users.findById(id); | ||
const cart = await Users.findCartById(id); | ||
res.status(200).json({ userId: user.id, cart: cart }); | ||
}); | ||
|
||
router.get('/:id/inventory', async (req, res) => { | ||
const id = req.params.id | ||
const user = await Users.findById(id) | ||
const profile = await Users.findProfile(id) | ||
router.get("/:id/inventory", async (req, res) => { | ||
const id = req.params.id; | ||
const user = await Users.findById(id); | ||
const profile = await Users.findProfile(id); | ||
|
||
if (profile.is_grower) { | ||
const inventory = await Users.findInventoryById(id) | ||
res.status(200).json({ userId: user.id, inventory: inventory }) | ||
const inventory = await Users.findInventoryById(id); | ||
res.status(200).json({ userId: user.id, inventory: inventory }); | ||
} else { | ||
res.status(400).json({ errorMessage: 'You must be a registered grower' }) | ||
res.status(400).json({ errorMessage: "You must be a registered grower" }); | ||
} | ||
}) | ||
module.exports = router | ||
}); | ||
module.exports = router; |
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
763d215
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: