From 390ca4938b9dbda211b0b0646cf18817f952014f Mon Sep 17 00:00:00 2001 From: StephBerg86 Date: Thu, 20 Aug 2020 19:28:29 +0200 Subject: [PATCH] final commit --- routers/auth.js | 12 ++++++-- routers/travel.js | 8 ++--- seeders/20200812193540-traveltips.js | 44 +++++++++++++++++++++------- 3 files changed, 47 insertions(+), 17 deletions(-) diff --git a/routers/auth.js b/routers/auth.js index 48b4e5d..6b812c9 100644 --- a/routers/auth.js +++ b/routers/auth.js @@ -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) { @@ -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) { @@ -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") { diff --git a/routers/travel.js b/routers/travel.js index 90cee37..72ce6d0 100644 --- a/routers/travel.js +++ b/routers/travel.js @@ -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 }); }); @@ -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) { @@ -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 @@ -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 }); diff --git a/seeders/20200812193540-traveltips.js b/seeders/20200812193540-traveltips.js index 8ddf932..477153c 100644 --- a/seeders/20200812193540-traveltips.js +++ b/seeders/20200812193540-traveltips.js @@ -15,7 +15,7 @@ module.exports = { createdAt: new Date(), updatedAt: new Date(), userId: 1, - countryId: 1, + countryId: 3, }, { title: "Visit the golden temple", @@ -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", @@ -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", @@ -51,7 +51,7 @@ module.exports = { createdAt: new Date(), updatedAt: new Date(), userId: 1, - countryId: 1, + countryId: 3, }, { title: "Sleep in a capsule", @@ -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", @@ -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, }, ], {}