From 90ac31cf96fd650ef89669ce33b0315a2e3260e9 Mon Sep 17 00:00:00 2001 From: Sergey Peshkov Date: Mon, 9 Sep 2019 23:42:40 +0300 Subject: [PATCH] feat(application): add email to applications. Fixes MEMB-606 --- lib/applications.js | 12 ++++++------ lib/constants.js | 1 + .../20190909203402-add-emails-to-application.js | 10 ++++++++++ models/Application.js | 8 ++++++++ 4 files changed, 25 insertions(+), 6 deletions(-) create mode 100644 migrations/20190909203402-add-emails-to-application.js diff --git a/lib/applications.js b/lib/applications.js index 47d010ce..0d44f743 100644 --- a/lib/applications.js +++ b/lib/applications.js @@ -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); } diff --git a/lib/constants.js b/lib/constants.js index 8f4989f3..821b9c66 100644 --- a/lib/constants.js +++ b/lib/constants.js @@ -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', diff --git a/migrations/20190909203402-add-emails-to-application.js b/migrations/20190909203402-add-emails-to-application.js new file mode 100644 index 00000000..8e705bbf --- /dev/null +++ b/migrations/20190909203402-add-emails-to-application.js @@ -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') +}; diff --git a/models/Application.js b/models/Application.js index 189ead17..17bb6c94 100644 --- a/models/Application.js +++ b/models/Application.js @@ -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,