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

  // validate
  if ( (!params.id || params.id === '') && (!params.uri || params.uri === '') ) {
    return 'You must enter a valid id or uri'
  }

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

  debug(params)

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

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

    var sql
    if (params.id) {
      sql = 'INSERT into Fragment values (:id, :start, :end, NULL, NOW(), 1)'
    } else {
      sql = 'INSERT into Fragment Select m.id, :start, :end, NULL, NOW(), u.id from Media m, User u where m.uri = :uri and u.uri = :webid'
    }
    debug(sql)

    conn.query(sql, { replacements: { "id" : params.id, "start" : params.start, "end" : params.end, "uri" : params.uri, "webid" : params.webid } }).then(function(ret){
      return resolve({"ret" : ret, "conn" : conn})
    }).catch(function(err) {
      return reject({"err" : err, "conn" : conn})
    })

  })

}
function addFragment(params, config, conn) {

  // validate
  if ( (!params.id || params.id === '') && (!params.uri || params.uri === '') ) {
    return 'You must enter a valid id or uri'
  }

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

  debug(params)

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

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

    var sql
    if (params.id) {
      sql = 'INSERT into Fragment values (:id, :start, :end, NULL, NOW(), 1)'
    } else {
      sql = 'INSERT into Fragment Select m.id, :start, :end, NULL, NOW(), u.id from Media m, User u where m.uri = :uri and u.uri = :webid'
    }
    debug(sql)

    conn.query(sql, { replacements: { "id" : params.id, "start" : params.start, "end" : params.end, "uri" : params.uri, "webid" : params.webid } }).then(function(ret){
      return resolve({"ret" : ret, "conn" : conn})
    }).catch(function(err) {
      return reject({"err" : err, "conn" : conn})
    })

  })

}
function addFragment ( params , config , conn ) { // validate if ( ( ! params . id || params . id === '' ) && ( ! params . uri || params . uri === '' ) ) { return 'You must enter a valid id or uri' } // defaults config = config || require ( '../config/config.js' ) debug ( params ) // main return new Promise ( ( resolve , reject ) => { if ( ! conn ) { var conn = wc_db . getConnection ( config . db ) } var sql if ( params . id ) { sql = 'INSERT into Fragment values (:id, :start, :end, NULL, NOW(), 1)' } else { sql = 'INSERT into Fragment Select m.id, :start, :end, NULL, NOW(), u.id from Media m, User u where m.uri = :uri and u.uri = :webid' } debug ( sql ) conn . query ( sql , { replacements : { "id" : params . id , "start" : params . start , "end" : params . end , "uri" : params . uri , "webid" : params . webid } } ) . then ( function ( ret ) { return resolve ( { "ret" : ret , "conn" : conn } ) } ) . catch ( function ( err ) { return reject ( { "err" : err , "conn" : conn } ) } ) } ) }
Adds a fragment to the database
@param {Object} params  The parameter info.
@param {Object} config  The optional config.
@param {Object} conn    The optional db connection.
@return {Object} Promise with success or fail.
Adds a fragment to the database