Posted By

yeahstyle on 04/15/16


Tagged


Versions (?)

Bet Class


 / Published in: JavaScript
 

A standard bet class

  1. class Bet {
  2. constructor(model) {
  3.  
  4. // from: Bookies || from: Tips
  5. // ----------------------------------------------------------- //
  6. let id = model.id || model.tip_hash,
  7. selectionName = model.selectionName || model.selection,
  8. event = model.event || model.eventname,
  9. marketName = model.marketName || model.market_name,
  10. eventTime = model.eventTime || model.event_start_unix_timestamp;
  11.  
  12. // Standard Bet Rendering
  13. this.id = id ? id : this.throwError('id');
  14. this.selectionName = selectionName ? selectionName : this.throwError('selectionName');
  15. this.event = event ? event : this.throwError('event');
  16. this.marketName = marketName ? marketName : this.throwError('marketName');
  17. this.eventTime = eventTime ? eventTime : this.throwError('eventTime');
  18.  
  19. // Tip Data (should come from Tip)
  20. this.outcomeId = model.vc_outcome_id ? model.vc_outcome_id : this.throwError('outcomeId');
  21. this.formattedOdds = model.formattedOdds ? model.formattedOdds : this.throwError('formattedOdds');
  22. this.cssSport = model.cssSport ? model.cssSport : this.throwError('cssSport');
  23. this.selection = this.selectionName;
  24. this.sport = model.sport ? model.sport : this.throwError('sport');
  25. this.sport_alias = model.sport_alias ? model.sport_alias : this.throwError('sport_alias');
  26. this.vc_event_id = model.vc_event_id ? model.vc_event_id : this.throwError('vc_event_id');
  27. this.handicap_market = model.handicap_market ? model.handicap_market : this.throwError('handicap_market');
  28. this.handicap = model.handicap ? model.handicap : null;
  29. this.outcome_name = model.outcome_name ? model.outcome_name : this.throwError('outcome_name');
  30. this.params = model.params ? model.params : this.throwError('params');
  31.  
  32. if (!this.params.sportId ||
  33. !this.params.catId ||
  34. !this.params.leagueId ||
  35. !this.params.eventId ||
  36. !this.params.tipId) {
  37. throw new Error('BetFactory: one of the following options are missing from params -> tip | tip.sport | tip.menu_cat | menu_league | tip-eventname | tip.tip_hash');
  38. }
  39. }
  40.  
  41. throwError(missing) {
  42. throw new Error('BetFactory requires a valid model! (missing ' + missing + ')');
  43. return null;
  44. }
  45. }

Report this snippet  

You need to login to post a comment.