diff --git a/update-password.js b/update-password.js index 5b94e93c..fbafe10b 100644 --- a/update-password.js +++ b/update-password.js @@ -1,6 +1,10 @@ // load dependencies const logger = require('winston'); const db = require('./models'); // require our models for syncing +// configure logging +const config = require('./config/speechConfig.js'); +const logLevel = config.logging.logLevel; +require('./config/loggerConfig.js')(logger, logLevel); const userName = process.argv[2]; logger.debug('user name:', userName); @@ -22,20 +26,22 @@ db.sequelize.sync() // sync sequelize if (!user) { throw new Error('no user found'); } - return user.comparePassword(oldPassword, (passwordErr, isMatch) => { - if (passwordErr) { - throw passwordErr; - } - if (!isMatch) { - throw new Error('Incorrect old password.'); - } - logger.debug('Password was a match, updating password'); - return user.changePassword(newPassword); + return new Promise((resolve, reject) => { + user.comparePassword(oldPassword, (passwordErr, isMatch) => { + if (passwordErr) { + return reject(passwordErr); + } + if (!isMatch) { + return reject('Incorrect old password.'); + } + logger.debug('Password was a match, updating password'); + return resolve(user.changePassword(newPassword)); + }); }); }) .then(() => { logger.debug('Password successfully updated'); }) .catch((error) => { - logger.error('error:', error); + logger.error(error); });