lib/qpm_media.js
function getTopImages(params, config, conn) {


  // defaults
  config = config || require('../config/config.js')

  var limit = 10
  if (!isNaN(params.limit)) {
    limit = params.limit
  }


  // main
  return new Promise((resolve, reject) => {

    if (!conn) {
      var conn = wc_db.getConnection(config.db)
    }

    var sql
    if (params.reviewer) {
      sql = 'SELECT * from Rating where reviewer = :reviewer order by rating DESC LIMIT :limit '
    } else {
      sql = 'SELECT uri, avg(rating) rating from Rating group by uri order by rating DESC LIMIT :limit '
    }

    conn.query(sql, { replacements: { "reviewer" : params.reviewer, "limit" : params.limit } }).then(function(ret){
      return resolve({"ret" : ret, "conn" : conn})
    }).catch(function(err) {
      return reject({"err" : err, "conn" : conn})
    })

  })

}
function getTopImages(params, config, conn) {


  // defaults
  config = config || require('../config/config.js')

  var limit = 10
  if (!isNaN(params.limit)) {
    limit = params.limit
  }


  // main
  return new Promise((resolve, reject) => {

    if (!conn) {
      var conn = wc_db.getConnection(config.db)
    }

    var sql
    if (params.reviewer) {
      sql = 'SELECT * from Rating where reviewer = :reviewer order by rating DESC LIMIT :limit '
    } else {
      sql = 'SELECT uri, avg(rating) rating from Rating group by uri order by rating DESC LIMIT :limit '
    }

    conn.query(sql, { replacements: { "reviewer" : params.reviewer, "limit" : params.limit } }).then(function(ret){
      return resolve({"ret" : ret, "conn" : conn})
    }).catch(function(err) {
      return reject({"err" : err, "conn" : conn})
    })

  })

}
function getTopImages ( params , config , conn ) { // defaults config = config || require ( '../config/config.js' ) var limit = 10 if ( ! isNaN ( params . limit ) ) { limit = params . limit } // main return new Promise ( ( resolve , reject ) => { if ( ! conn ) { var conn = wc_db . getConnection ( config . db ) } var sql if ( params . reviewer ) { sql = 'SELECT * from Rating where reviewer = :reviewer order by rating DESC LIMIT :limit ' } else { sql = 'SELECT uri, avg(rating) rating from Rating group by uri order by rating DESC LIMIT :limit ' } conn . query ( sql , { replacements : { "reviewer" : params . reviewer , "limit" : params . limit } } ) . then ( function ( ret ) { return resolve ( { "ret" : ret , "conn" : conn } ) } ) . catch ( function ( err ) { return reject ( { "err" : err , "conn" : conn } ) } ) } ) }
Get the top images
@param {Object} rating  The rating to add.
@param {Object} config  The optional config.
@param {Object} conn    The optional db connection.
@return {Object} Promise with success or fail.
Get the top images