app/services/stockService.js
/**
   * Adds a company with the given name to the watch list and
   * fetches articles from discovery
   * @param {string} companyName
   * @returns {promise}
   */
Adds a company with the given name to the watch list and
fetches articles from discovery
@param {string} companyName
@returns {promise}
Adds a company with the given name to the watch list and fetches articles from discovery @param { string } companyName @returns { promise }
addCompany(companyName) {
    return new Promise((resolve, reject) => {
      db.search().then((rows)  => {
        var docs = rows.map(function(row) {
          return row.doc;
        });
        if (docs.length >= config.MAX_COMPANIES) {
          reject('No more than ' + config.MAX_COMPANIES + ' companies may be watched.');
        } else {
          if (utils.findStockDatum(docs, companyName)) {
            reject('This company is already being watched');
          } else {
            stockUpdate.run([companyName]).then((results) => {
              var newResult = utils.findStockDatum(results, companyName);
              resolve(newResult);
            }).catch((error) => {
              reject(error);
            });
          }
        }
      });
    });
  }
addCompany ( companyName ) { return new Promise ( ( resolve , reject ) => { db . search ( ) . then ( ( rows ) => { var docs = rows . map ( function ( row ) { return row . doc ; } ) ; if ( docs . length >= config . MAX_COMPANIES ) { reject ( 'No more than ' + config . MAX_COMPANIES + ' companies may be watched.' ) ; } else { if ( utils . findStockDatum ( docs , companyName ) ) { reject ( 'This company is already being watched' ) ; } else { stockUpdate . run ( [ companyName ] ) . then ( ( results ) => { var newResult = utils . findStockDatum ( results , companyName ) ; resolve ( newResult ) ; } ) . catch ( ( error ) => { reject ( error ) ; } ) ; } } } ) ; } ) ; }
Adds a company with the given name to the watch list and
 fetches articles from discovery
 @param {string} companyName
 @returns {promise}
Adds a company with the given name to the watch list and fetches articles from discovery @param { string } companyName @returns { promise }
//check that the company is not already being watched