content-item.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. class ContentItem {
  4. constructor(hash, props) {
  5. this.data = props;
  6. this.hash = hash;
  7. this.type = props.type;
  8. this.title = props.title;
  9. this.text = props.text;
  10. if (props.myTags) {
  11. this.myTagsWithoutAll = props.myTags.filter(x => x !== 'all');
  12. }
  13. else {
  14. this.myTagsWithoutAll = [];
  15. }
  16. if (props.price != null && !isNaN(Number(props.price))) {
  17. this.price = Number(props.price);
  18. this.priceFormatted = this.formatCents(this.price);
  19. }
  20. this.allLinks = props.links || [];
  21. this.userLinks = this.allLinks.filter(x => !x.rel.startsWith('.'));
  22. this.systemLinks = this.allLinks.filter(x => x.rel.startsWith('.'));
  23. this.fromTarget = this.allLinks.filter(x => x.rel === '.from').map(x => x.target)[0];
  24. this.toTarget = this.allLinks.filter(x => x.rel === '.to').map(x => x.target)[0];
  25. this.fromContactId = this.allLinks.filter(x => x.rel === '.from-contact-id').map(x => x.target)[0];
  26. this.toContactId = this.allLinks.filter(x => x.rel === '.to-contact-id').map(x => x.target)[0];
  27. this.media = this.allLinks.filter(x => x.rel === '.media').map(x => x.target)[0];
  28. if (this.fromTarget && this.toTarget && this.media) {
  29. this.repliable = true;
  30. }
  31. else {
  32. this.repliable = false;
  33. }
  34. }
  35. formatCents(price) {
  36. if (price == null || price === 0) {
  37. return 'free';
  38. }
  39. let dollars = `${price / 100}`;
  40. if (dollars.match(/\..$/)) {
  41. dollars += '0';
  42. }
  43. return '$' + dollars;
  44. }
  45. }
  46. exports.ContentItem = ContentItem;
  47. //# sourceMappingURL=content-item.js.map