module.exports = {


    friendlyName: 'Modify',
  
  
    description: 'Modify User.',
  
  
    inputs: {
    /*  id:{
        type:'string',
        required: true
      },*/
      
      
      password:{
        type:'string',
        required: true
      },
      newPassword:{
        type:'string',
        required: true
      },
      
    },
  
  
    exits: {
      notFound:{
        statusCode:404
      },
  
    },
  
  
    fn: async function ({password, newPassword},exits) {

        let idApplicant = this.req.token.id
        let roleApplicant = this.req.token.user.role
    
  
        let user = await User.find({id: idApplicant, password: password}).then(_.first)
        console.log('user', user)
        if (!user){
          return exits.notFound({ message: "Votre actuel mot de passe est incorrect, Veuillez réessayer!" })
        }

        let userUpd = await User.update({id: idApplicant}, {password: newPassword, passwordUpdated: true}).fetch()
        //console.log('USER', user, userUpd, idApplicant)
 
            // All done.
            return exits.success({message:'Done !'});
    }
    
  
  };
  