Skip to content
Snippets Groups Projects

Sprint #12

Merged Bogdan Cochior requested to merge develop into master
185 files
+ 4274
5003
Compare changes
  • Side-by-side
  • Inline
Files
185
@@ -3,35 +3,12 @@ const logger = require('@pubsweet/logger')
const helpers = require('./helpers')
module.exports = {
setupAssignEmail: async (req, email, res, role) => {
const url = `${req.protocol}://${req.get('host')}`
let emailType
switch (role) {
case 'handlingEditor':
emailType = 'assign-handling-editor'
break
case 'author':
emailType = 'add-author'
break
default:
return res
.status(400)
.json({ error: `Role ${role} cannot be used with an assigned email` })
}
try {
await mailService.setupAssignEmail(email, emailType, url)
return res.status(200).json({})
} catch (e) {
logger.error(e)
return res.status(500).json({ error: 'Email could not be sent.' })
}
},
setupNewUserEmail: async (req, res, email, role, UserModel) => {
setupNewUserEmail: async ({ dashboardUrl, res, email, role, UserModel }) => {
let user
try {
user = await UserModel.findByEmail(email)
} catch (e) {
const notFoundError = await helpers.handleNotFoundError(e, 'user')
const notFoundError = await helpers.handleNotFoundError(e, 'User')
return res.status(notFoundError.status).json({
error: notFoundError.message,
})
@@ -39,9 +16,8 @@ module.exports = {
if (user.passwordResetToken === undefined) {
return res
.status(400)
.json({ error: 'User does not have a password reset token' })
.json({ error: 'User does not have a password reset token.' })
}
const url = `${req.protocol}://${req.get('host')}`
let emailType
switch (role) {
case 'handlingEditor':
@@ -54,11 +30,16 @@ module.exports = {
break
default:
return res.status(400).json({
error: `Role ${role} cannot be used with a password reset email`,
error: `Role ${role} cannot be used with a password reset email.`,
})
}
try {
await mailService.setupInviteEmail(user, emailType, url)
await mailService.sendSimpleEmail({
toEmail: user.email,
user,
emailType,
dashboardUrl,
})
return res.status(200).json({})
} catch (e) {
logger.error(e)