//const Informations = require("../../models/Informations");

//const Informations = require("../../models/Informations");

module.exports = {


    friendlyName: 'Find',
  
  
    description: 'Find user.',
  
  
    inputs: {
      search: {
        type: 'string'
      },
      role: {
        type: 'number'
      },
      section: {
        type: 'number'
      },
    },
  
  
    exits: {
      encryptionError: {
        statusCode: 500
      }
    },
  
  
    fn: async function (inputs, exits) {
  
  
      let users = await User.find({ roleSlug: 'PRESTATAIRE_ROLE', nomPrenom: { 'contains': inputs.search || '' }}).sort('nom ASC')
        .then(users => {
          return Promise.all(users.map(async user => {
            //console.log('USER', user)
  
            let section = await Section.find({ id: user.section }).then(_.first)
            if (section) {
              user.section = section
            } 
            
            let role = await Role.find({ id: user.role }).then(_.first)
            if (role) {
              user.role = role
            } 
  
            return { ...user, /*..._.omit(person,['id','user'])*/ };
          }))//.then(users => users.filter(user => user && user.userInfo.agence !== inputs.codAgence)) //.then(users => users.filter(user => user && user.role.id !== clientRole.id))
        })
      // All done.
      return exits.success(users);
  
    }
  
  
  };
  