@@ -19,7 +19,7 @@ const LOGIN_ATTEMPTS = 5
1919 * Generates a token
2020 * @param {Object } user - user object
2121 */
22- const generateToken = user => {
22+ const generateToken = ( user ) => {
2323 // Gets expiration time
2424 const expiration =
2525 Math . floor ( Date . now ( ) / 1000 ) + 60 * process . env . JWT_EXPIRATION_IN_MINUTES
@@ -42,7 +42,7 @@ const generateToken = user => {
4242 * Creates an object with user info
4343 * @param {Object } req - request object
4444 */
45- const setUserInfo = req => {
45+ const setUserInfo = ( req ) => {
4646 let user = {
4747 _id : req . _id ,
4848 name : req . name ,
@@ -73,7 +73,7 @@ const saveUserAccessAndReturnToken = async (req, user) => {
7373 browser : utils . getBrowserInfo ( req ) ,
7474 country : utils . getCountry ( req )
7575 } )
76- userAccess . save ( err => {
76+ userAccess . save ( ( err ) => {
7777 if ( err ) {
7878 reject ( utils . buildErrObject ( 422 , err . message ) )
7979 }
@@ -91,7 +91,7 @@ const saveUserAccessAndReturnToken = async (req, user) => {
9191 * Blocks a user by setting blockExpires to the specified date based on constant HOURS_TO_BLOCK
9292 * @param {Object } user - user object
9393 */
94- const blockUser = async user => {
94+ const blockUser = async ( user ) => {
9595 return new Promise ( ( resolve , reject ) => {
9696 user . blockExpires = addHours ( new Date ( ) , HOURS_TO_BLOCK )
9797 user . save ( ( err , result ) => {
@@ -109,7 +109,7 @@ const blockUser = async user => {
109109 * Saves login attempts to dabatabse
110110 * @param {Object } user - user object
111111 */
112- const saveLoginAttemptsToDB = async user => {
112+ const saveLoginAttemptsToDB = async ( user ) => {
113113 return new Promise ( ( resolve , reject ) => {
114114 user . save ( ( err , result ) => {
115115 if ( err ) {
@@ -126,14 +126,14 @@ const saveLoginAttemptsToDB = async user => {
126126 * Checks that login attempts are greater than specified in constant and also that blockexpires is less than now
127127 * @param {Object } user - user object
128128 */
129- const blockIsExpired = user =>
129+ const blockIsExpired = ( user ) =>
130130 user . loginAttempts > LOGIN_ATTEMPTS && user . blockExpires <= new Date ( )
131131
132132/**
133133 *
134134 * @param {Object } user - user object.
135135 */
136- const checkLoginAttemptsAndBlockExpires = async user => {
136+ const checkLoginAttemptsAndBlockExpires = async ( user ) => {
137137 return new Promise ( ( resolve , reject ) => {
138138 // Let user try to login again after blockexpires, resets user loginAttempts
139139 if ( blockIsExpired ( user ) ) {
@@ -157,7 +157,7 @@ const checkLoginAttemptsAndBlockExpires = async user => {
157157 * Checks if blockExpires from user is greater than now
158158 * @param {Object } user - user object
159159 */
160- const userIsBlocked = async user => {
160+ const userIsBlocked = async ( user ) => {
161161 return new Promise ( ( resolve , reject ) => {
162162 if ( user . blockExpires > new Date ( ) ) {
163163 reject ( utils . buildErrObject ( 409 , 'BLOCKED_USER' ) )
@@ -170,7 +170,7 @@ const userIsBlocked = async user => {
170170 * Finds user by email
171171 * @param {string } email - user´s email
172172 */
173- const findUser = async email => {
173+ const findUser = async ( email ) => {
174174 return new Promise ( ( resolve , reject ) => {
175175 User . findOne (
176176 {
@@ -189,7 +189,7 @@ const findUser = async email => {
189189 * Finds user by ID
190190 * @param {string } id - user´s id
191191 */
192- const findUserById = async userId => {
192+ const findUserById = async ( userId ) => {
193193 return new Promise ( ( resolve , reject ) => {
194194 User . findById ( userId , ( err , item ) => {
195195 utils . itemNotFound ( err , item , reject , 'USER_DOES_NOT_EXIST' )
@@ -202,7 +202,7 @@ const findUserById = async userId => {
202202 * Adds one attempt to loginAttempts, then compares loginAttempts with the constant LOGIN_ATTEMPTS, if is less returns wrong password, else returns blockUser function
203203 * @param {Object } user - user object
204204 */
205- const passwordsDoNotMatch = async user => {
205+ const passwordsDoNotMatch = async ( user ) => {
206206 user . loginAttempts += 1
207207 await saveLoginAttemptsToDB ( user )
208208 return new Promise ( ( resolve , reject ) => {
@@ -219,7 +219,7 @@ const passwordsDoNotMatch = async user => {
219219 * Registers a new user in database
220220 * @param {Object } req - request object
221221 */
222- const registerUser = async req => {
222+ const registerUser = async ( req ) => {
223223 return new Promise ( ( resolve , reject ) => {
224224 const user = new User ( {
225225 name : req . name ,
@@ -256,7 +256,7 @@ const returnRegisterToken = (item, userInfo) => {
256256 * Checks if verification id exists for user
257257 * @param {string } id - verification id
258258 */
259- const verificationExists = async id => {
259+ const verificationExists = async ( id ) => {
260260 return new Promise ( ( resolve , reject ) => {
261261 User . findOne (
262262 {
@@ -275,7 +275,7 @@ const verificationExists = async id => {
275275 * Verifies an user
276276 * @param {Object } user - user object
277277 */
278- const verifyUser = async user => {
278+ const verifyUser = async ( user ) => {
279279 return new Promise ( ( resolve , reject ) => {
280280 user . verified = true
281281 user . save ( ( err , item ) => {
@@ -327,7 +327,7 @@ const updatePassword = async (password, user) => {
327327 * Finds user by email to reset password
328328 * @param {string } email - user email
329329 */
330- const findUserToResetPassword = async email => {
330+ const findUserToResetPassword = async ( email ) => {
331331 return new Promise ( ( resolve , reject ) => {
332332 User . findOne (
333333 {
@@ -345,7 +345,7 @@ const findUserToResetPassword = async email => {
345345 * Checks if a forgot password verification exists
346346 * @param {string } id - verification id
347347 */
348- const findForgotPassword = async id => {
348+ const findForgotPassword = async ( id ) => {
349349 return new Promise ( ( resolve , reject ) => {
350350 ForgotPassword . findOne (
351351 {
@@ -364,7 +364,7 @@ const findForgotPassword = async id => {
364364 * Creates a new password forgot
365365 * @param {Object } req - request object
366366 */
367- const saveForgotPassword = async req => {
367+ const saveForgotPassword = async ( req ) => {
368368 return new Promise ( ( resolve , reject ) => {
369369 const forgot = new ForgotPassword ( {
370370 email : req . body . email ,
@@ -386,7 +386,7 @@ const saveForgotPassword = async req => {
386386 * Builds an object with created forgot password object, if env is development or testing exposes the verification
387387 * @param {Object } item - created forgot password object
388388 */
389- const forgotPasswordResponse = item => {
389+ const forgotPasswordResponse = ( item ) => {
390390 let data = {
391391 msg : 'RESET_EMAIL_SENT' ,
392392 email : item . email
@@ -421,7 +421,7 @@ const checkPermissions = async (data, next) => {
421421 * Gets user id from token
422422 * @param {string } token - Encrypted and encoded token
423423 */
424- const getUserIdFromToken = async token => {
424+ const getUserIdFromToken = async ( token ) => {
425425 return new Promise ( ( resolve , reject ) => {
426426 // Decrypts, verifies and decode token
427427 jwt . verify ( auth . decrypt ( token ) , process . env . JWT_SECRET , ( err , decoded ) => {
@@ -563,7 +563,7 @@ exports.getRefreshToken = async (req, res) => {
563563 * Roles authorization function called by route
564564 * @param {Array } roles - roles specified on the route
565565 */
566- exports . roleAuthorization = roles => async ( req , res , next ) => {
566+ exports . roleAuthorization = ( roles ) => async ( req , res , next ) => {
567567 try {
568568 const data = {
569569 id : req . user . _id ,
0 commit comments