Skip to content

Commit

Permalink
bug(sendgrid):Fix sendgrid email bug
Browse files Browse the repository at this point in the history
Use try catch to console log sendgrid email limit error

[Finishes #167215236]
  • Loading branch information
chokonaira committed Jul 11, 2019
1 parent 467cbd7 commit 059e2b8
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 11 deletions.
25 changes: 14 additions & 11 deletions src/controllers/Auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,20 @@ class AuthController {
const result = await User.create(values);
const { id, isVerified } = result;
const token = await generateToken({ id, email, isVerified });

const url = `${req.protocol}://${req.get('host')}/api/v1/auth/verify/${token}`;
const message = template(userName, url);
const subject = 'Welcome to Authors Haven';
await sendEmail
.sendEmail(
'do_not_reply@authorhaven.com',
email,
subject,
message
);
try {
const url = `${req.protocol}://${req.get('host')}/api/v1/auth/verify/${token}`;
const message = template(userName, url);
const subject = 'Welcome to Authors Haven';
await sendEmail
.sendEmail(
'do_not_reply@authorhaven.com',
email,
subject,
message
);
} catch (err) {
console.log(err);
}

return res.status(201).json({
status: 201,
Expand Down
42 changes: 42 additions & 0 deletions src/db/migrations/30181008085213-create-comment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
module.exports = {
up: (queryInterface, Sequelize) => queryInterface.createTable('Comments', {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER
},
commentBody: {
type: Sequelize.TEXT
},
userId: {
type: Sequelize.INTEGER,
onDelete: 'CASCADE',
references: {
model: 'Users',
key: 'id',
as: 'userId'
}
},
articleId: {
type: Sequelize.INTEGER,
onDelete: 'CASCADE',
references: {
model: 'Articles',
key: 'id',
as: 'articleId'
}
},
createdAt: {
allowNull: false,
type: Sequelize.DATE,
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP')
},
updatedAt: {
allowNull: false,
type: Sequelize.DATE,
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP')
}
}),
down: queryInterface => queryInterface.dropTable('Comments')
};
42 changes: 42 additions & 0 deletions src/db/models/comment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
const comment = (sequelize, DataTypes) => {
const Comment = sequelize.define('Comment', {
commentBody: {
type: DataTypes.STRING
},
userId: {
type: DataTypes.INTEGER,
onDelete: 'CASCADE',
references: {
model: 'Users',
key: 'id',
as: 'userId'
}
},
articleId: {
type: DataTypes.INTEGER,
onDelete: 'CASCADE',
references: {
model: 'Articles',
key: 'id',
as: 'articleId'
}
},
});

Comment.associate = (models) => {
// associations can be defined here
Comment.belongsTo(models.User, {
as: 'userComments',
foriegnKey: 'userId',
onDelete: 'CASCADE'
});
Comment.belongsTo(models.Article, {
foreignKey: 'articleId',
as: 'article',
onDelete: 'CASCADE',
onUpdate: 'CASCADE'
});
};
return Comment;
};
export default comment;

0 comments on commit 059e2b8

Please sign in to comment.