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

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

  params = params || {}
  params.webid = params.webid || 'http://melvincarvalho.com/#me'

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

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

    var sql = "select f.* from Fragment f join User u on f.user_id = u.id where u.uri = :webid order by lastSeen desc LIMIT 1;"
    var fragLastSeen
    var mediaLastSeen
    var val

    debug('getLastSeen', sql, params)

    conn.query(sql, { replacements: { "webid" : params.webid } }).then(function(frag){
      var sql = "select r.* from Rating r join User u on u.id = r.reviewer_id and u.uri = :webid order by datePublished desc LIMIT 1;"
      debug('getLastSeen', sql, params)
      debug(frag)
      val = frag
      fragLastSeen = frag[0][0].lastSeen
      debug(fragLastSeen)
      return conn.query(sql, { replacements: { "webid" : params.webid } })
    }).then(function(media) {
      debug(media)
      mediaLastSeen = media[0][0].datePublished
      debug(mediaLastSeen)
      if (mediaLastSeen > fragLastSeen) {
        debug('media is latest : ' + media.lastSeen)
        return resolve({"ret" : media, "conn" : conn})
      } else {
        debug('frag is latest : ' + media.lastSeen)
        return resolve({"ret" : val, "conn" : conn})
      }
    }).catch(function(err) {
      return reject({"err" : err, "conn" : conn})
    })

  })

}
function getLastSeen(params, config, conn) {

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

  params = params || {}
  params.webid = params.webid || 'http://melvincarvalho.com/#me'

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

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

    var sql = "select f.* from Fragment f join User u on f.user_id = u.id where u.uri = :webid order by lastSeen desc LIMIT 1;"
    var fragLastSeen
    var mediaLastSeen
    var val

    debug('getLastSeen', sql, params)

    conn.query(sql, { replacements: { "webid" : params.webid } }).then(function(frag){
      var sql = "select r.* from Rating r join User u on u.id = r.reviewer_id and u.uri = :webid order by datePublished desc LIMIT 1;"
      debug('getLastSeen', sql, params)
      debug(frag)
      val = frag
      fragLastSeen = frag[0][0].lastSeen
      debug(fragLastSeen)
      return conn.query(sql, { replacements: { "webid" : params.webid } })
    }).then(function(media) {
      debug(media)
      mediaLastSeen = media[0][0].datePublished
      debug(mediaLastSeen)
      if (mediaLastSeen > fragLastSeen) {
        debug('media is latest : ' + media.lastSeen)
        return resolve({"ret" : media, "conn" : conn})
      } else {
        debug('frag is latest : ' + media.lastSeen)
        return resolve({"ret" : val, "conn" : conn})
      }
    }).catch(function(err) {
      return reject({"err" : err, "conn" : conn})
    })

  })

}
function getLastSeen ( params , config , conn ) { // defaults config = config || require ( '../config/config.js' ) params = params || { } params . webid = params . webid || 'http://melvincarvalho.com/#me' // main return new Promise ( ( resolve , reject ) => { if ( ! conn ) { var conn = wc_db . getConnection ( config . db ) } var sql = "select f.* from Fragment f join User u on f.user_id = u.id where u.uri = :webid order by lastSeen desc LIMIT 1;" var fragLastSeen var mediaLastSeen var val debug ( 'getLastSeen' , sql , params ) conn . query ( sql , { replacements : { "webid" : params . webid } } ) . then ( function ( frag ) { var sql = "select r.* from Rating r join User u on u.id = r.reviewer_id and u.uri = :webid order by datePublished desc LIMIT 1;" debug ( 'getLastSeen' , sql , params ) debug ( frag ) val = frag fragLastSeen = frag [ 0 ] [ 0 ] . lastSeen debug ( fragLastSeen ) return conn . query ( sql , { replacements : { "webid" : params . webid } } ) } ) . then ( function ( media ) { debug ( media ) mediaLastSeen = media [ 0 ] [ 0 ] . datePublished debug ( mediaLastSeen ) if ( mediaLastSeen > fragLastSeen ) { debug ( 'media is latest : ' + media . lastSeen ) return resolve ( { "ret" : media , "conn" : conn } ) } else { debug ( 'frag is latest : ' + media . lastSeen ) return resolve ( { "ret" : val , "conn" : conn } ) } } ) . catch ( function ( err ) { return reject ( { "err" : err , "conn" : conn } ) } ) } ) }
Get get the last seen item
@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 get the last seen item