packages/udaru-core/lib/ops/userOps.js
function readUser (params, cb) {
      let promise = null
      if (typeof cb !== 'function') [promise, cb] = asyncify()

      const { id, organizationId } = params
      let user

      const tasks = []

      tasks.push((next) => {
        Joi.validate({ id, organizationId }, validationRules.readUser, (err) => {
          if (err) return next(Boom.badRequest(err))
          next()
        })
      })

      tasks.push((next) => {
        const sqlQuery = SQL`
          SELECT id, name, org_id, metadata
          FROM users
          WHERE id = ${id}
          AND org_id = ${organizationId}
        `
        db.query(sqlQuery, (err, result) => {
          if (err) return next(Boom.badImplementation(err))
          if (result.rowCount === 0) return next(Boom.notFound(`User ${id} not found`))

          user = mapping.user(result.rows[0])
          next()
        })
      })

      tasks.push((next) => {
        const sqlQuery = SQL`
          SELECT teams.id, teams.name
          FROM team_members mem, teams
          WHERE mem.user_id = ${id} AND mem.team_id = teams.id
          ORDER BY UPPER(teams.name)
        `
        db.query(sqlQuery, (err, result) => {
          if (err) return next(Boom.badImplementation(err))

          user.teams = result.rows.map(mapping.team.simple)
          next()
        })
      })

      tasks.push((next) => {
        const sqlQuery = SQL`
          SELECT pol.id, pol.name, pol.version, user_pol.variables, user_pol.policy_instance
          FROM user_policies user_pol, policies pol
          WHERE user_pol.user_id = ${id} AND user_pol.policy_id = pol.id
          ORDER BY UPPER(pol.name)
        `
        db.query(sqlQuery, (err, result) => {
          if (err) return next(Boom.badImplementation(err))

          user.policies = result.rows.map(mapping.policy.simple)
          next()
        })
      })

      async.series(tasks, (err) => {
        if (err) return cb(err)

        return cb(null, user)
      })

      return promise
    }
function readUser (params, cb) {
      let promise = null
      if (typeof cb !== 'function') [promise, cb] = asyncify()

      const { id, organizationId } = params
      let user

      const tasks = []

      tasks.push((next) => {
        Joi.validate({ id, organizationId }, validationRules.readUser, (err) => {
          if (err) return next(Boom.badRequest(err))
          next()
        })
      })

      tasks.push((next) => {
        const sqlQuery = SQL`
          SELECT id, name, org_id, metadata
          FROM users
          WHERE id = ${id}
          AND org_id = ${organizationId}
        `
        db.query(sqlQuery, (err, result) => {
          if (err) return next(Boom.badImplementation(err))
          if (result.rowCount === 0) return next(Boom.notFound(`User ${id} not found`))

          user = mapping.user(result.rows[0])
          next()
        })
      })

      tasks.push((next) => {
        const sqlQuery = SQL`
          SELECT teams.id, teams.name
          FROM team_members mem, teams
          WHERE mem.user_id = ${id} AND mem.team_id = teams.id
          ORDER BY UPPER(teams.name)
        `
        db.query(sqlQuery, (err, result) => {
          if (err) return next(Boom.badImplementation(err))

          user.teams = result.rows.map(mapping.team.simple)
          next()
        })
      })

      tasks.push((next) => {
        const sqlQuery = SQL`
          SELECT pol.id, pol.name, pol.version, user_pol.variables, user_pol.policy_instance
          FROM user_policies user_pol, policies pol
          WHERE user_pol.user_id = ${id} AND user_pol.policy_id = pol.id
          ORDER BY UPPER(pol.name)
        `
        db.query(sqlQuery, (err, result) => {
          if (err) return next(Boom.badImplementation(err))

          user.policies = result.rows.map(mapping.policy.simple)
          next()
        })
      })

      async.series(tasks, (err) => {
        if (err) return cb(err)

        return cb(null, user)
      })

      return promise
    }
function readUser ( params , cb ) { let promise = null if ( typeof cb !== 'function' ) [ promise , cb ] = asyncify ( ) const { id , organizationId } = params let user const tasks = [ ] tasks . push ( ( next ) => { Joi . validate ( { id , organizationId } , validationRules . readUser , ( err ) => { if ( err ) return next ( Boom . badRequest ( err ) ) next ( ) } ) } ) tasks . push ( ( next ) => { const sqlQuery = SQL ` ${ id } ${ organizationId } ` db . query ( sqlQuery , ( err , result ) => { if ( err ) return next ( Boom . badImplementation ( err ) ) if ( result . rowCount === 0 ) return next ( Boom . notFound ( ` ${ id } ` ) ) user = mapping . user ( result . rows [ 0 ] ) next ( ) } ) } ) tasks . push ( ( next ) => { const sqlQuery = SQL ` ${ id } ` db . query ( sqlQuery , ( err , result ) => { if ( err ) return next ( Boom . badImplementation ( err ) ) user . teams = result . rows . map ( mapping . team . simple ) next ( ) } ) } ) tasks . push ( ( next ) => { const sqlQuery = SQL ` ${ id } ` db . query ( sqlQuery , ( err , result ) => { if ( err ) return next ( Boom . badImplementation ( err ) ) user . policies = result . rows . map ( mapping . policy . simple ) next ( ) } ) } ) async . series ( tasks , ( err ) => { if ( err ) return cb ( err ) return cb ( null , user ) } ) return promise }
Get user details

@param  {Object}   params { id, organizationId }
@param  {Function} cb
Get user details