You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

profiler.js 3.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. // NOTE: just have all the tags in one place
  16. this.tags = profile.tags.filter(t => t.tag_category !== 'reveal')
  17. // TODO: generalize this for multiple images, and languages
  18. this.profile_description = ''
  19. this.profile_media = []
  20. this.profile_languages = []
  21. this.profile_prefs = {}
  22. this.image = ''
  23. this.blurb = ''
  24. // TODO: Use reveal tags to add or remove information from profile!
  25. // TODO: ---
  26. // TODO: Use reveal tags to rebuild profile based on group/membership
  27. // TODO: and include for certain profiles
  28. this.reveal = profile.tags.filter(t => t.tag_category == 'reveal')
  29. // TODO: filter these correctly
  30. if (profile?.responses?.length && includeResponses) {
  31. // [] of all "profile" responses
  32. this.responses = profile.responses
  33. // image, language, duration, presence, blurb, urgency, role, pronouns, distance
  34. const prefs = [
  35. 'zipcode',
  36. 'duration',
  37. 'presence',
  38. 'urgency',
  39. 'pronouns',
  40. 'distance',
  41. ]
  42. const prefsKeys = config.prefKeys
  43. prefs.forEach((pref, i) => {
  44. this.profile_prefs[pref] = this.responses.find(
  45. r => r.response_key_id === prefsKeys[i],
  46. )
  47. })
  48. this.profile_description = this.responses.find(
  49. r => r.response_key_id === config.blurbKey,
  50. ).val
  51. this.profile_media = this.responses
  52. .filter(r => r.response_key_id === config.mediaKey)
  53. .map(r => r.val)
  54. this.profile_languages = this.responses
  55. .filter(r => r.response_key_id === config.langKey)
  56. .map(r => r.val)
  57. }
  58. }
  59. }
  60. const _makeCompleteProfile = (
  61. profileEntry,
  62. type,
  63. tagLookup,
  64. includeResponses,
  65. ) => {
  66. profileEntry.tags = profileEntry.tags.map(tag => tagLookup[tag.tag_id])
  67. return new CompleteProfile(profileEntry, includeResponses, type)
  68. }
  69. const makeOrderedCompleteProfiles = (
  70. orderedProfileIds,
  71. profilesEntries,
  72. type,
  73. includeResponses,
  74. tagLookup,
  75. ) => {
  76. const completeProfiles = []
  77. orderedProfileIds.forEach(pid => {
  78. profilesEntries.forEach(entry => {
  79. if (entry.profile_id != pid) return
  80. completeProfiles.push(
  81. _makeCompleteProfile(entry, type, tagLookup, includeResponses),
  82. )
  83. })
  84. })
  85. return completeProfiles
  86. }
  87. const makeCompleteFromProfileEntries = (profilesEntries, type, tagLookup) =>
  88. profilesEntries.map(entry => _makeCompleteProfile(entry, type, tagLookup))
  89. module.exports = {
  90. CompleteProfile,
  91. makeOrderedCompleteProfiles,
  92. makeCompleteFromProfileEntries,
  93. }