Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

profiler.js 3.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. const config = require('../../../db/data-generator/config.json')
  2. /**
  3. * Class to hold our retrieved profile information
  4. * in a convenient wrapper
  5. * !: This needs to match the responseSchema in profiles.js
  6. */
  7. class CompleteProfile {
  8. constructor(profile, includeResponses = false, type) {
  9. this.user_id = profile.user_id // int user_id
  10. this.profile_id = profile.profile_id // int profile_id
  11. this.user_name = profile.user.user_name // string user_name
  12. this.user_email = profile.user.user_email
  13. this.responses = []
  14. this.user_type = type
  15. this.tags = profile.tags.filter(t => t.tag_category != 'reveal')
  16. // TODO: generalize this for multiple images, and languages
  17. this.profile_description = ''
  18. this.profile_media = []
  19. this.profile_languages = []
  20. this.profile_prefs = {}
  21. // TODO: Use reveal tags to add or remove information from profile!
  22. // TODO: ---
  23. // TODO: Use reveal tags to rebuild profile based on group/membership
  24. // TODO: and include for certain profiles
  25. this.reveal = profile.tags.filter(t => t.tag_category == 'reveal')
  26. // TODO: filter these correctly
  27. if (profile?.responses?.length && includeResponses) {
  28. // [] of all "profile" responses
  29. this.responses = profile.responses
  30. // image, language, duration, presence, blurb, urgency, role, pronouns, distance
  31. const prefs = [
  32. 'zipcode',
  33. 'duration',
  34. 'presence',
  35. 'urgency',
  36. 'role',
  37. 'pronouns',
  38. 'distance',
  39. ]
  40. const prefsKeys = config.prefKeys
  41. prefs.forEach((pref, i) => {
  42. this.profile_prefs[pref] = this.responses.find(
  43. r => r.response_key_id === prefsKeys[i],
  44. )
  45. })
  46. this.profile_description = this.responses.find(
  47. r => r.response_key_id === config.blurbKey,
  48. ).val
  49. this.profile_media = this.responses
  50. .filter(r => r.response_key_id === config.mediaKey)
  51. .map(r => r.val)
  52. this.profile_languages = this.responses
  53. .filter(r => r.response_key_id === config.langKey)
  54. .map(r => r.val)
  55. }
  56. }
  57. }
  58. const _makeCompleteProfile = (
  59. profileEntry,
  60. type,
  61. tagLookup,
  62. includeResponses,
  63. ) => {
  64. profileEntry.tags = profileEntry.tags.map(tag => tagLookup[tag.tag_id])
  65. return new CompleteProfile(profileEntry, includeResponses, type)
  66. }
  67. const makeOrderedCompleteProfiles = (
  68. orderedProfileIds,
  69. profilesEntries,
  70. type,
  71. includeResponses,
  72. tagLookup,
  73. ) => {
  74. const completeProfiles = []
  75. orderedProfileIds.forEach(pid => {
  76. profilesEntries.forEach(entry => {
  77. if (entry.profile_id != pid) return
  78. completeProfiles.push(
  79. _makeCompleteProfile(entry, type, tagLookup, includeResponses),
  80. )
  81. })
  82. })
  83. return completeProfiles
  84. }
  85. const makeCompleteFromProfileEntries = (profilesEntries, type, tagLookup) =>
  86. profilesEntries.map(entry => _makeCompleteProfile(entry, type, tagLookup))
  87. module.exports = {
  88. CompleteProfile,
  89. makeOrderedCompleteProfiles,
  90. makeCompleteFromProfileEntries,
  91. }