diff --git a/migrations/20200812165028-create-user.js b/migrations/20200812165028-create-user.js index 9a4ef4b..eca90c8 100644 --- a/migrations/20200812165028-create-user.js +++ b/migrations/20200812165028-create-user.js @@ -1,33 +1,36 @@ -'use strict'; +"use strict"; module.exports = { up: async (queryInterface, Sequelize) => { - await queryInterface.createTable('users', { + await queryInterface.createTable("users", { id: { allowNull: false, autoIncrement: true, primaryKey: true, - type: Sequelize.INTEGER + type: Sequelize.INTEGER, }, name: { - type: Sequelize.STRING + type: Sequelize.STRING, }, email: { - type: Sequelize.STRING + type: Sequelize.STRING, }, password: { - type: Sequelize.STRING + type: Sequelize.STRING, + }, + image: { + type: Sequelize.STRING, }, createdAt: { allowNull: false, - type: Sequelize.DATE + type: Sequelize.DATE, }, updatedAt: { allowNull: false, - type: Sequelize.DATE - } + type: Sequelize.DATE, + }, }); }, down: async (queryInterface, Sequelize) => { - await queryInterface.dropTable('users'); - } -}; \ No newline at end of file + await queryInterface.dropTable("users"); + }, +}; diff --git a/models/user.js b/models/user.js index 0c1f6e8..be7d879 100644 --- a/models/user.js +++ b/models/user.js @@ -16,6 +16,7 @@ module.exports = (sequelize, DataTypes) => { name: DataTypes.STRING, email: DataTypes.STRING, password: DataTypes.STRING, + image: DataTypes.STRING, }, { sequelize, diff --git a/routers/auth.js b/routers/auth.js index 4d9dd68..48b4e5d 100644 --- a/routers/auth.js +++ b/routers/auth.js @@ -33,7 +33,11 @@ router.post("/login", async (req, res, next) => { } delete user.dataValues["password"]; // don't send back the password hash - const token = toJWT({ userId: user.id }); + const token = toJWT({ + userId: user.id, + email: user.email, + name: user.name, + }); return res.status(200).send({ token, ...user.dataValues }); } catch (error) { console.log(error); @@ -42,7 +46,7 @@ router.post("/login", async (req, res, next) => { }); router.post("/signup", async (req, res) => { - const { email, name, password } = req.body; + const { email, name, password, image } = req.body; if (!email || !password || !name) { return res.status(400).send("Please provide an email, password and a name"); } @@ -52,6 +56,7 @@ router.post("/signup", async (req, res) => { email, name, password: bcrypt.hashSync(password, SALT_ROUNDS), + image, }); delete newUser.dataValues["password"]; // don't send back the password hash diff --git a/routers/travel.js b/routers/travel.js index b1f4549..90cee37 100644 --- a/routers/travel.js +++ b/routers/travel.js @@ -42,7 +42,7 @@ router.get("/traveltip/:id", async (req, res) => { }); router.post("/traveltip", async (req, res) => { - const { title, description, category, countryId, image } = req.body; + const { title, description, category, countryId, userId, image } = req.body; if (!title || !description) { return res @@ -55,6 +55,7 @@ router.post("/traveltip", async (req, res) => { description, category, countryId, + userId, image, }); diff --git a/seeders/20200812165832-users.js b/seeders/20200812165832-users.js index 1b5068c..c8eabb9 100644 --- a/seeders/20200812165832-users.js +++ b/seeders/20200812165832-users.js @@ -10,21 +10,27 @@ module.exports = { { name: "Stephanie", email: "Steph@test.nl", - password: bcrypt.hashSync("123x", SALT_ROUNDS), + password: bcrypt.hashSync("123", SALT_ROUNDS), + image: + "https://scontent-amt2-1.xx.fbcdn.net/v/t1.0-9/69910964_3719992764694294_1826466700950721444_n.jpg?_nc_cat=101&_nc_sid=85a577&_nc_ohc=4tnnlPuy3fUAX89cRPp&_nc_ht=scontent-amt2-1.xx&oh=93f82b6ce49c25fceac84d8d442222b6&oe=5F629716", createdAt: new Date(), updatedAt: new Date(), }, { - name: "dummy", - email: "d@ummy.com", - password: bcrypt.hashSync("dummy1", SALT_ROUNDS), + name: "Peter", + email: "peter@test.com", + password: bcrypt.hashSync("123", SALT_ROUNDS), + image: + "https://images.pexels.com/photos/1250426/pexels-photo-1250426.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260", createdAt: new Date(), updatedAt: new Date(), }, { - name: "test", - email: "test@test.com", - password: bcrypt.hashSync("test1", SALT_ROUNDS), + name: "Kim", + email: "kim@test.com", + password: bcrypt.hashSync("123", SALT_ROUNDS), + image: + "https://images.pexels.com/photos/415829/pexels-photo-415829.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260", createdAt: new Date(), updatedAt: new Date(), }, diff --git a/seeders/20200812181317-countries.js b/seeders/20200812181317-countries.js index 360567c..5b943d9 100644 --- a/seeders/20200812181317-countries.js +++ b/seeders/20200812181317-countries.js @@ -6,12 +6,17 @@ module.exports = { "countries", [ { - name: "Bahamas", + name: "Argentina", createdAt: new Date(), updatedAt: new Date(), }, { - name: "Japan", + name: "Australia", + createdAt: new Date(), + updatedAt: new Date(), + }, + { + name: "Bahamas", createdAt: new Date(), updatedAt: new Date(), }, @@ -20,11 +25,176 @@ module.exports = { createdAt: new Date(), updatedAt: new Date(), }, + { + name: "Cuba", + createdAt: new Date(), + updatedAt: new Date(), + }, + { + name: "China", + createdAt: new Date(), + updatedAt: new Date(), + }, + { + name: "Denmark", + createdAt: new Date(), + updatedAt: new Date(), + }, + { + name: "Dominican Republic", + createdAt: new Date(), + updatedAt: new Date(), + }, + { + name: "Ecuador", + createdAt: new Date(), + updatedAt: new Date(), + }, + { + name: "Ethiopia", + createdAt: new Date(), + updatedAt: new Date(), + }, + { + name: "Fiji", + createdAt: new Date(), + updatedAt: new Date(), + }, + { + name: "Finland", + createdAt: new Date(), + updatedAt: new Date(), + }, + { + name: "Germany", + createdAt: new Date(), + updatedAt: new Date(), + }, + { + name: "Guatemala", + createdAt: new Date(), + updatedAt: new Date(), + }, + { + name: "Haiti", + createdAt: new Date(), + updatedAt: new Date(), + }, + { + name: "Honduras", + createdAt: new Date(), + updatedAt: new Date(), + }, { name: "Iceland", createdAt: new Date(), updatedAt: new Date(), }, + { + name: "Indonesia", + createdAt: new Date(), + updatedAt: new Date(), + }, + { + name: "Japan", + createdAt: new Date(), + updatedAt: new Date(), + }, + { + name: "Jamaica", + createdAt: new Date(), + updatedAt: new Date(), + }, + { + name: "Kenya", + createdAt: new Date(), + updatedAt: new Date(), + }, + { + name: "Kuwait", + createdAt: new Date(), + updatedAt: new Date(), + }, + { + name: "Laos", + createdAt: new Date(), + updatedAt: new Date(), + }, + { + name: "Luxembourg", + createdAt: new Date(), + updatedAt: new Date(), + }, + { + name: "Malaysia", + createdAt: new Date(), + updatedAt: new Date(), + }, + { + name: "Mexico", + createdAt: new Date(), + updatedAt: new Date(), + }, + { + name: "Namibia", + createdAt: new Date(), + updatedAt: new Date(), + }, + { + name: "New Zealand", + createdAt: new Date(), + updatedAt: new Date(), + }, + { + name: "Peru", + createdAt: new Date(), + updatedAt: new Date(), + }, + { + name: "Philippines", + createdAt: new Date(), + updatedAt: new Date(), + }, + { + name: "Singapore", + createdAt: new Date(), + updatedAt: new Date(), + }, + { + name: "South Afrika", + createdAt: new Date(), + updatedAt: new Date(), + }, + { + name: "Thailand", + createdAt: new Date(), + updatedAt: new Date(), + }, + { + name: "Tanzania", + createdAt: new Date(), + updatedAt: new Date(), + }, + { + name: "United Kingdom", + createdAt: new Date(), + updatedAt: new Date(), + }, + { + name: "United States", + createdAt: new Date(), + updatedAt: new Date(), + }, + { + name: "Vietnam", + createdAt: new Date(), + updatedAt: new Date(), + }, + { + name: "Zimbabwe", + createdAt: new Date(), + updatedAt: new Date(), + }, ], {} );