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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. const config = require('../../../db/data-generator/config.json')
  2. const tagger = require('./tagger')
  3. /**
  4. * Class to hold our retrieved profile information
  5. * in a convenient wrapper
  6. * !: This needs to match the responseSchema in profiles.js
  7. */
  8. class CompleteProfile {
  9. constructor(profile, type, includeResponses = false) {
  10. this.user_id = profile.user_id // int user_id
  11. this.profile_id = profile.profile_id // int profile_id
  12. this.user_name = profile.user.user_name // string user_name
  13. this.user_email = profile.user.user_email
  14. this.responses = []
  15. this.user_type = type
  16. this.tags = profile.tags.filter(t => t.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. // 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.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. 'role',
  38. 'pronouns',
  39. 'distance',
  40. ]
  41. const prefsKeys = config.prefKeys
  42. prefs.forEach((pref, i) => {
  43. this.profile_prefs[pref] = this.responses.filter(
  44. r => r.response_key_id === prefsKeys[i],
  45. )[0]
  46. })
  47. this.profile_description = this.responses
  48. .filter(r => r.response_key_id === config.blurbKey)
  49. .map(r => r.val)[0]
  50. this.profile_media = this.responses
  51. .filter(r => r.response_key_id === config.mediaKey)
  52. .map(r => r.val)
  53. this.profile_languages = this.responses
  54. .filter(r => r.response_key_id === config.langKey)
  55. .map(r => r.val)
  56. }
  57. }
  58. }
  59. const makeCompleteProfiles = (
  60. profileIdArray,
  61. profilesEntries,
  62. type,
  63. includeResponses,
  64. tagLookup,
  65. ) => {
  66. const completeProfiles = []
  67. profileIdArray.forEach(pid => {
  68. profilesEntries.forEach(entry => {
  69. if (entry.profile_id == pid) {
  70. const complete = new CompleteProfile(
  71. entry,
  72. type,
  73. includeResponses,
  74. )
  75. tagger.setProfileTags(entry, complete, tagLookup)
  76. completeProfiles.push(complete)
  77. }
  78. })
  79. })
  80. return completeProfiles
  81. }
  82. const makeCompleteProfilesFromProfile = (profilesEntries, type, tagLookup) => {
  83. profilesEntries.forEach(profile => {
  84. tagger.setProfileTags(profile, profile, tagLookup)
  85. })
  86. //** Get responses asociated with each profile_id */
  87. return profilesEntries.map(profile => {
  88. return new CompleteProfile(profile, type)
  89. })
  90. }
  91. module.exports = {
  92. CompleteProfile,
  93. makeCompleteProfiles,
  94. makeCompleteProfilesFromProfile,
  95. }