lib/qpm_media.js
function addRating(rating, config, conn) {

  // validate
  if (!rating.uri || rating.uri === '') {
    return 'You must enter a valid uri'
  }
  if (!rating.reviewer || rating.reviewer === '') {
    return 'You must enter a valid reviewer'
  }
  if (isNaN(rating.rating)) {
    return 'You must enter a valid rating'
  }

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

  debug(rating)

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

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

    insertRating(rating, config, conn).then(function(ret) {
      return resolve({"ret": ret, "conn": conn})
    }).catch(function(err) {
      debug('addRating', 'updating instead of insert')
      return updateRating(rating, config, conn)
    }).then(function(ret){
      return resolve({"ret": ret, "conn": conn})
    }).catch(function(){
      return reject({"ret": ret, "conn": conn})
    })


  })

}
function addRating(rating, config, conn) {

  // validate
  if (!rating.uri || rating.uri === '') {
    return 'You must enter a valid uri'
  }
  if (!rating.reviewer || rating.reviewer === '') {
    return 'You must enter a valid reviewer'
  }
  if (isNaN(rating.rating)) {
    return 'You must enter a valid rating'
  }

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

  debug(rating)

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

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

    insertRating(rating, config, conn).then(function(ret) {
      return resolve({"ret": ret, "conn": conn})
    }).catch(function(err) {
      debug('addRating', 'updating instead of insert')
      return updateRating(rating, config, conn)
    }).then(function(ret){
      return resolve({"ret": ret, "conn": conn})
    }).catch(function(){
      return reject({"ret": ret, "conn": conn})
    })


  })

}
function addRating ( rating , config , conn ) { // validate if ( ! rating . uri || rating . uri === '' ) { return 'You must enter a valid uri' } if ( ! rating . reviewer || rating . reviewer === '' ) { return 'You must enter a valid reviewer' } if ( isNaN ( rating . rating ) ) { return 'You must enter a valid rating' } // defaults config = config || require ( '../config/config.js' ) debug ( rating ) // main return new Promise ( ( resolve , reject ) => { if ( ! conn ) { var conn = wc_db . getConnection ( config . db ) } insertRating ( rating , config , conn ) . then ( function ( ret ) { return resolve ( { "ret" : ret , "conn" : conn } ) } ) . catch ( function ( err ) { debug ( 'addRating' , 'updating instead of insert' ) return updateRating ( rating , config , conn ) } ) . then ( function ( ret ) { return resolve ( { "ret" : ret , "conn" : conn } ) } ) . catch ( function ( ) { return reject ( { "ret" : ret , "conn" : conn } ) } ) } ) }
Adds rating to the database
@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.
Adds rating to the database