content-item.js 1.7 KB

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