Skip to content

Commit

Permalink
feat(application): add email to applications. Fixes MEMB-606
Browse files Browse the repository at this point in the history
  • Loading branch information
serge1peshcoff committed Sep 9, 2019
1 parent 21a5172 commit 90ac31c
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
12 changes: 6 additions & 6 deletions lib/applications.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,17 @@ exports.setApplication = async (req, res) => {
delete req.body.board_comment;
delete req.body.status;

req.body.first_name = req.user.first_name;
req.body.last_name = req.user.last_name;
req.body.body_name = req.user.bodies.find((b) => b.id === req.body.body_id).name;
req.body.user_id = req.user.id;
req.body.event_id = req.event.id;
req.body.email = req.user.user.email;

let application = await Application.findOne({ where: { event_id: req.event.id, user_id: req.user.id } });
if (application) {
await application.update(req.body);
} else {
req.body.first_name = req.user.first_name;
req.body.last_name = req.user.last_name;
req.body.body_name = req.user.bodies.find((b) => b.id === req.body.body_id).name;
req.body.user_id = req.user.id;
req.body.event_id = req.event.id;

application = await Application.create(req.body);
}

Expand Down
1 change: 1 addition & 0 deletions lib/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module.exports = {
body_name: 'Body name',
first_name: 'First name',
last_name: 'Last name',
email: 'Email',
status: 'Status',
board_comment: 'Board comment',
created_at: 'Created at',
Expand Down
10 changes: 10 additions & 0 deletions migrations/20190909203402-add-emails-to-application.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = {
up: async (queryInterface, Sequelize) => {
await queryInterface.addColumn(
'applications',
'email',
{ type: Sequelize.STRING, allowNull: false, defaultValue: 'Not set.' }
);
},
down: async (queryInterface) => queryInterface.removeColumn('applications', 'email')
};
8 changes: 8 additions & 0 deletions models/Application.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ const Application = sequelize.define('application', {
notEmpty: { msg: 'Last name should be set.' }
}
},
email: {
allowNull: false,
type: Sequelize.STRING,
defaultValue: '',
validate: {
notEmpty: { msg: 'Email should be set.' }
}
},
body_name: {
allowNull: false,
type: Sequelize.STRING,
Expand Down

0 comments on commit 90ac31c

Please sign in to comment.