Вы не можете выбрать более 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 = 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. 'pronouns',
  37. 'distance',
  38. ]
  39. const prefsKeys = config.prefKeys
  40. prefs.forEach((pref, i) => {
  41. this.profile_prefs[pref] = this.responses.find(
  42. r => r.response_key_id === prefsKeys[i],
  43. )
  44. })
  45. this.profile_description = this.responses.find(
  46. r => r.response_key_id === config.blurbKey,
  47. ).val
  48. this.profile_media = this.responses
  49. .filter(r => r.response_key_id === config.mediaKey)
  50. .map(r => r.val)
  51. this.profile_languages = this.responses
  52. .filter(r => r.response_key_id === config.langKey)
  53. .map(r => r.val)
  54. }
  55. }
  56. }
  57. const _makeCompleteProfile = (
  58. profileEntry,
  59. type,
  60. tagLookup,
  61. includeResponses,
  62. ) => {
  63. profileEntry.tags = profileEntry.tags.map(tag => tagLookup[tag.tag_id])
  64. return new CompleteProfile(profileEntry, includeResponses, type)
  65. }
  66. const makeOrderedCompleteProfiles = (
  67. orderedProfileIds,
  68. profilesEntries,
  69. type,
  70. includeResponses,
  71. tagLookup,
  72. ) => {
  73. const completeProfiles = []
  74. orderedProfileIds.forEach(pid => {
  75. profilesEntries.forEach(entry => {
  76. if (entry.profile_id != pid) return
  77. completeProfiles.push(
  78. _makeCompleteProfile(entry, type, tagLookup, includeResponses),
  79. )
  80. })
  81. })
  82. return completeProfiles
  83. }
  84. const makeCompleteFromProfileEntries = (profilesEntries, type, tagLookup) =>
  85. profilesEntries.map(entry => _makeCompleteProfile(entry, type, tagLookup))
  86. module.exports = {
  87. CompleteProfile,
  88. makeOrderedCompleteProfiles,
  89. makeCompleteFromProfileEntries,
  90. }