src/controllers/authenticationController.js
/**
   * @description This helps a new User to create credentials
   * @param  {object} req - The request object
   * @param  {object} res - The response object
   * @returns  {object} The response object
   */
@description This helps a new User to create credentials
@param  {object} req - The request object
@param  {object} res - The response object
@returns  {object} The response object
@description This helps a new User to create credentials @param { object } req - The request object @param { object } res - The response object @returns { object } The response object
static async register(req, res) {
    try {
      const {
        firstName,
        lastName,
        userName,
        password,
        email
      } = req.body;
      const user = await User.create(
        {
          user_name: userName,
          first_name: firstName,
          last_name: lastName,
          email,
          password: await hashPassword(password)
        },
        {
          fields: [
            'user_name',
            'email',
            'password',
            'first_name',
            'last_name',
            'role'
          ]
        }
      );
      const newUser = {
        id: user.id,
        email: user.email,
        role: user.role
      };
      const token = jwt.sign(newUser, process.env.KEY);
      const data = {
        user: {
          email: user.email,
          userName: user.user_name,
        },
        token
      };
      const mail = new Mailer({
        to: data.user.email,
        header: 'Verify your email address',
        messageHeader: `Hi, <strong>${user.user_name}!</strong>`,
        messageBody: 'Thank you for creating an account, Just click the link below to verify your account.',
        optionLink: `${process.env.FRONTEND_URL}/api/auth/confirmation/resend`,
        Button: true
      });
      mail.InitButton({
        text: 'Verify my account',
        link: `${process.env.FRONTEND_URL}/confirmEmail?token=${token}`
      });
      await mail.sendMail();
      const response = new Response(res, 201, 'User sucessfully registered', data);
      response.sendSuccessResponse();
    } catch (error) {
      DbErrorHandler.handleSignupError(res, error);
    }
  }
static async register ( req , res ) { try { const { firstName , lastName , userName , password , email } = req . body ; const user = await User . create ( { user_name : userName , first_name : firstName , last_name : lastName , email , password : await hashPassword ( password ) } , { fields : [ 'user_name' , 'email' , 'password' , 'first_name' , 'last_name' , 'role' ] } ) ; const newUser = { id : user . id , email : user . email , role : user . role } ; const token = jwt . sign ( newUser , process . env . KEY ) ; const data = { user : { email : user . email , userName : user . user_name , } , token } ; const mail = new Mailer ( { to : data . user . email , header : 'Verify your email address' , messageHeader : ` ${ user . user_name } ` , messageBody : 'Thank you for creating an account, Just click the link below to verify your account.' , optionLink : ` ${ process . env . FRONTEND_URL } ` , Button : true } ) ; mail . InitButton ( { text : 'Verify my account' , link : ` ${ process . env . FRONTEND_URL } ${ token } ` } ) ; await mail . sendMail ( ) ; const response = new Response ( res , 201 , 'User sucessfully registered' , data ) ; response . sendSuccessResponse ( ) ; } catch ( error ) { DbErrorHandler . handleSignupError ( res , error ) ; } }
@description This helps a new User to create credentials
 @param  {object} req - The request object
 @param  {object} res - The response object
 @returns  {object} The response object
@description This helps a new User to create credentials @param { object } req - The request object @param { object } res - The response object @returns { object } The response object