Skip to content

Commit

Permalink
final commit
Browse files Browse the repository at this point in the history
  • Loading branch information
StephBerg86 committed Aug 20, 2020
1 parent d0c06cc commit 390ca49
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 17 deletions.
12 changes: 9 additions & 3 deletions routers/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const { SALT_ROUNDS } = require("../config/constants");

const router = new Router();

router.post("/login", async (req, res, next) => {
router.post("/login", async (req, res) => {
try {
const { email, password } = req.body;
if (!email || !password) {
Expand All @@ -34,9 +34,10 @@ router.post("/login", async (req, res, next) => {

delete user.dataValues["password"]; // don't send back the password hash
const token = toJWT({
userId: user.id,
email: user.email,
id: user.id,
name: user.name,
image: user.image,
});
return res.status(200).send({ token, ...user.dataValues });
} catch (error) {
Expand All @@ -60,7 +61,12 @@ router.post("/signup", async (req, res) => {
});
delete newUser.dataValues["password"]; // don't send back the password hash

const token = toJWT({ userId: newUser.id });
const token = toJWT({
userId: newUser.id,
email: newUser.email,
image: newUser.image,
name: newUser.name,
});
res.status(201).json({ token, ...newUser.dataValues });
} catch (error) {
if (error.name === "SequelizeUniqueConstraintError") {
Expand Down
8 changes: 4 additions & 4 deletions routers/travel.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ router.get("/traveltip", async (req, res) => {
const tips = await Traveltip.findAndCountAll({
limit,
offset,
include: [Country],
include: [Country, User],
});
res.status(200).send({ message: "ok", tips });
});
Expand All @@ -31,7 +31,7 @@ router.get("/traveltip/:id", async (req, res) => {
}

const tip = await Traveltip.findByPk(id, {
include: [Country],
include: [Country, User],
});

if (tip === null) {
Expand All @@ -42,7 +42,7 @@ router.get("/traveltip/:id", async (req, res) => {
});

router.post("/traveltip", async (req, res) => {
const { title, description, category, countryId, userId, image } = req.body;
const { title, description, category, countryId, image, userId } = req.body;

if (!title || !description) {
return res
Expand All @@ -55,8 +55,8 @@ router.post("/traveltip", async (req, res) => {
description,
category,
countryId,
userId,
image,
userId,
});

return res.status(201).send({ message: "Travel tip created", tip });
Expand Down
44 changes: 34 additions & 10 deletions seeders/20200812193540-traveltips.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module.exports = {
createdAt: new Date(),
updatedAt: new Date(),
userId: 1,
countryId: 1,
countryId: 3,
},
{
title: "Visit the golden temple",
Expand All @@ -26,8 +26,8 @@ module.exports = {
category: "to do",
createdAt: new Date(),
updatedAt: new Date(),
userId: 1,
countryId: 2,
userId: 2,
countryId: 19,
},
{
title: "Eat Feijoada in Sao Paulo",
Expand All @@ -38,8 +38,8 @@ module.exports = {
category: "to eat",
createdAt: new Date(),
updatedAt: new Date(),
userId: 1,
countryId: 3,
userId: 3,
countryId: 4,
},
{
title: "Conch salad at the Bahamas",
Expand All @@ -51,7 +51,7 @@ module.exports = {
createdAt: new Date(),
updatedAt: new Date(),
userId: 1,
countryId: 1,
countryId: 3,
},
{
title: "Sleep in a capsule",
Expand All @@ -62,8 +62,8 @@ module.exports = {
category: "to stay",
createdAt: new Date(),
updatedAt: new Date(),
userId: 1,
countryId: 2,
userId: 2,
countryId: 19,
},
{
title: "Sleep in your rooftoptent in Iceland",
Expand All @@ -74,8 +74,32 @@ module.exports = {
category: "to stay",
createdAt: new Date(),
updatedAt: new Date(),
userId: 1,
countryId: 4,
userId: 3,
countryId: 17,
},
{
title: "Visit the most beautiful cenotes",
description:
"Yucatan is famous for it's cenotes. There are a lot and some of them are hidden. One of the most beutiful cenotes I've been to is Cenote Suytun. If you go in the morning or on a rainy day, you have the cenote to yourself.",
image:
"https://digitaltravelcouple.com/wp-content/uploads/2020/07/cenote-suytun-valladolid-1024x576.jpg",
category: "to do",
createdAt: new Date(),
updatedAt: new Date(),
userId: 3,
countryId: 26,
},
{
title: "Alma bar Isla Holbox",
description:
"The best place for a cocktail on Isla Holbox. You can enjoy an amazing view while swimming in the pool or drinking a cocktail.",
image:
"https://cdn.easy-rez.com/production/hotels/336cd3b3c89d5fe2a6db13e69e6f7358/public/.crops/alma_bar/alma_bar_12.jpg_1121x468.2147239263803_0-308.4049079754601.jpg",
category: "to eat",
createdAt: new Date(),
updatedAt: new Date(),
userId: 3,
countryId: 26,
},
],
{}
Expand Down

0 comments on commit 390ca49

Please sign in to comment.