Explorar el Código

Move add email function

GitOrigin-RevId: f45e28a9ed357427ae606ad5f8b59acaef54e31b
Jessica Lawshe hace 7 años
padre
commit
de8ac8ace7
Se han modificado 1 ficheros con 30 adiciones y 30 borrados
  1. 30 30
      services/web/app/src/Features/User/UserEmailsController.js

+ 30 - 30
services/web/app/src/Features/User/UserEmailsController.js

@@ -9,6 +9,35 @@ const logger = require('logger-sharelatex')
 const Errors = require('../Errors/Errors')
 const Errors = require('../Errors/Errors')
 const HttpErrors = require('@overleaf/o-error/http')
 const HttpErrors = require('@overleaf/o-error/http')
 
 
+function add(req, res, next) {
+  const userId = AuthenticationController.getLoggedInUserId(req)
+  const email = EmailHelper.parseEmail(req.body.email)
+  if (!email) {
+    return res.sendStatus(422)
+  }
+
+  const affiliationOptions = {
+    university: req.body.university,
+    role: req.body.role,
+    department: req.body.department
+  }
+  UserUpdater.addEmailAddress(userId, email, affiliationOptions, function(
+    error
+  ) {
+    if (error) {
+      return UserEmailsController._handleEmailError(error, req, res, next)
+    }
+    UserEmailsConfirmationHandler.sendConfirmationEmail(userId, email, function(
+      error
+    ) {
+      if (error) {
+        return next(error)
+      }
+      res.sendStatus(204)
+    })
+  })
+}
+
 module.exports = UserEmailsController = {
 module.exports = UserEmailsController = {
   list(req, res, next) {
   list(req, res, next) {
     const userId = AuthenticationController.getLoggedInUserId(req)
     const userId = AuthenticationController.getLoggedInUserId(req)
@@ -20,36 +49,7 @@ module.exports = UserEmailsController = {
     })
     })
   },
   },
 
 
-  add(req, res, next) {
-    const userId = AuthenticationController.getLoggedInUserId(req)
-    const email = EmailHelper.parseEmail(req.body.email)
-    if (!email) {
-      return res.sendStatus(422)
-    }
-
-    const affiliationOptions = {
-      university: req.body.university,
-      role: req.body.role,
-      department: req.body.department
-    }
-    UserUpdater.addEmailAddress(userId, email, affiliationOptions, function(
-      error
-    ) {
-      if (error) {
-        return UserEmailsController._handleEmailError(error, req, res, next)
-      }
-      UserEmailsConfirmationHandler.sendConfirmationEmail(
-        userId,
-        email,
-        function(error) {
-          if (error) {
-            return next(error)
-          }
-          res.sendStatus(204)
-        }
-      )
-    })
-  },
+  add,
 
 
   remove(req, res, next) {
   remove(req, res, next) {
     const userId = AuthenticationController.getLoggedInUserId(req)
     const userId = AuthenticationController.getLoggedInUserId(req)