Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

profiler.js 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 = 'hidden_name'// string user_name
  12. this.user_email = 'hidden@email.com'
  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. this.user_info = profile.user
  22. // TODO: Use reveal tags to add or remove information from profile!
  23. // TODO: ---
  24. // TODO: Use reveal tags to rebuild profile based on group/membership
  25. // TODO: and include for certain profiles
  26. this.reveal = profile.tags.filter(t => t.tag_category == 'reveal')
  27. // TODO: filter these correctly
  28. if (profile?.responses?.length && includeResponses) {
  29. // [] of all "profile" responses
  30. this.responses = profile.responses
  31. // image, language, duration, presence, blurb, urgency, role, pronouns, distance
  32. const prefs = [
  33. 'zipcode',
  34. 'duration',
  35. 'presence',
  36. 'urgency',
  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. }