packages/udaru-core/lib/ops/organizationOps.js
function list ({ limit, page }, cb) {
      let promise = null
      if (typeof cb !== 'function') [promise, cb] = asyncify('data', 'total')

      Joi.validate({ limit, page }, validationRules.list, (err) => {
        if (err) return cb(Boom.badRequest(err))

        const sqlQuery = SQL`
          WITH total AS (
            SELECT COUNT(*) AS cnt FROM organizations
          )
          SELECT o.*, t.cnt::INTEGER AS total
          FROM organizations AS o
          INNER JOIN total AS t ON 1=1
          ORDER BY UPPER(o.name)
        `

        if (limit) {
          sqlQuery.append(SQL` LIMIT ${limit}`)
        }
        if (limit && page) {
          let offset = (page - 1) * limit
          sqlQuery.append(SQL` OFFSET ${offset}`)
        }
        db.query(sqlQuery, function (err, result) {
          if (err) return cb(Boom.badImplementation(err))
          let total = result.rows.length > 0 ? result.rows[0].total : 0
          return cb(null, result.rows.map(mapping.organization), total)
        })
      })

      return promise
    }
function list ({ limit, page }, cb) {
      let promise = null
      if (typeof cb !== 'function') [promise, cb] = asyncify('data', 'total')

      Joi.validate({ limit, page }, validationRules.list, (err) => {
        if (err) return cb(Boom.badRequest(err))

        const sqlQuery = SQL`
          WITH total AS (
            SELECT COUNT(*) AS cnt FROM organizations
          )
          SELECT o.*, t.cnt::INTEGER AS total
          FROM organizations AS o
          INNER JOIN total AS t ON 1=1
          ORDER BY UPPER(o.name)
        `

        if (limit) {
          sqlQuery.append(SQL` LIMIT ${limit}`)
        }
        if (limit && page) {
          let offset = (page - 1) * limit
          sqlQuery.append(SQL` OFFSET ${offset}`)
        }
        db.query(sqlQuery, function (err, result) {
          if (err) return cb(Boom.badImplementation(err))
          let total = result.rows.length > 0 ? result.rows[0].total : 0
          return cb(null, result.rows.map(mapping.organization), total)
        })
      })

      return promise
    }
function list ( { limit , page } , cb ) { let promise = null if ( typeof cb !== 'function' ) [ promise , cb ] = asyncify ( 'data' , 'total' ) Joi . validate ( { limit , page } , validationRules . list , ( err ) => { if ( err ) return cb ( Boom . badRequest ( err ) ) const sqlQuery = SQL ` ` if ( limit ) { sqlQuery . append ( SQL ` ${ limit } ` ) } if ( limit && page ) { let offset = ( page - 1 ) * limit sqlQuery . append ( SQL ` ${ offset } ` ) } db . query ( sqlQuery , function ( err , result ) { if ( err ) return cb ( Boom . badImplementation ( err ) ) let total = result . rows . length > 0 ? result . rows [ 0 ] . total : 0 return cb ( null , result . rows . map ( mapping . organization ) , total ) } ) } ) return promise }
Fetch all organizations

@param  {Object} params must contain both `limit` and `page` for pagination. Page is 1-indexed.
@param  {Function} cb
Fetch all organizations