Skip to content

Commit

Permalink
added image to user and changed seeds
Browse files Browse the repository at this point in the history
  • Loading branch information
StephBerg86 committed Aug 19, 2020
1 parent 9ba22d0 commit d0c06cc
Show file tree
Hide file tree
Showing 6 changed files with 210 additions and 24 deletions.
27 changes: 15 additions & 12 deletions migrations/20200812165028-create-user.js
Original file line number Diff line number Diff line change
@@ -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');
}
};
await queryInterface.dropTable("users");
},
};
1 change: 1 addition & 0 deletions models/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ module.exports = (sequelize, DataTypes) => {
name: DataTypes.STRING,
email: DataTypes.STRING,
password: DataTypes.STRING,
image: DataTypes.STRING,
},
{
sequelize,
Expand Down
9 changes: 7 additions & 2 deletions routers/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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");
}
Expand All @@ -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

Expand Down
3 changes: 2 additions & 1 deletion routers/travel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -55,6 +55,7 @@ router.post("/traveltip", async (req, res) => {
description,
category,
countryId,
userId,
image,
});

Expand Down
20 changes: 13 additions & 7 deletions seeders/20200812165832-users.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,27 @@ module.exports = {
{
name: "Stephanie",
email: "[email protected]",
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: "[email protected]",
password: bcrypt.hashSync("dummy1", SALT_ROUNDS),
name: "Peter",
email: "[email protected]",
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: "[email protected]",
password: bcrypt.hashSync("test1", SALT_ROUNDS),
name: "Kim",
email: "[email protected]",
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(),
},
Expand Down
174 changes: 172 additions & 2 deletions seeders/20200812181317-countries.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
},
Expand All @@ -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(),
},
],
{}
);
Expand Down

0 comments on commit d0c06cc

Please sign in to comment.