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

      let organization
      const tasks = []

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

      tasks.push((next) => {
        const sqlQuery = SQL`
          SELECT *
          FROM organizations
          WHERE id = ${id}
        `
        db.query(sqlQuery, (err, result) => {
          if (err) return next(Boom.badImplementation(err))
          if (result.rowCount === 0) return next(Boom.notFound(`Organization ${id} not found`))

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

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

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

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

        return cb(null, organization)
      })

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

      let organization
      const tasks = []

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

      tasks.push((next) => {
        const sqlQuery = SQL`
          SELECT *
          FROM organizations
          WHERE id = ${id}
        `
        db.query(sqlQuery, (err, result) => {
          if (err) return next(Boom.badImplementation(err))
          if (result.rowCount === 0) return next(Boom.notFound(`Organization ${id} not found`))

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

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

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

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

        return cb(null, organization)
      })

      return promise
    }
function readById ( id , cb ) { let promise = null if ( typeof cb !== 'function' ) [ promise , cb ] = asyncify ( ) let organization const tasks = [ ] tasks . push ( ( next ) => { Joi . validate ( id , validationRules . readById , ( err ) => { if ( err ) return next ( Boom . badRequest ( err ) ) next ( ) } ) } ) tasks . push ( ( next ) => { const sqlQuery = SQL ` ${ id } ` db . query ( sqlQuery , ( err , result ) => { if ( err ) return next ( Boom . badImplementation ( err ) ) if ( result . rowCount === 0 ) return next ( Boom . notFound ( ` ${ id } ` ) ) organization = mapping . organization ( result . rows [ 0 ] ) next ( ) } ) } ) tasks . push ( ( next ) => { const sqlQuery = SQL ` ${ id } ` db . query ( sqlQuery , ( err , result ) => { if ( err ) return next ( Boom . badImplementation ( err ) ) organization . policies = result . rows . map ( mapping . policy . simple ) next ( ) } ) } ) async . series ( tasks , ( err ) => { if ( err ) return cb ( err ) return cb ( null , organization ) } ) return promise }
Fetch data for an organization

@param  {String}   id
@param  {Function} cb
Fetch data for an organization