| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- const config = require('../../../db/data-generator/config.json')
-
- /**
- * Class to hold our retrieved profile information
- * in a convenient wrapper
- * !: This needs to match the responseSchema in profiles.js
- */
- class CompleteProfile {
- constructor(profile, includeResponses = false, type) {
- this.user_id = profile.user_id // int user_id
- this.profile_id = profile.profile_id // int profile_id
- this.user_name = profile.user.user_name // string user_name
- this.user_email = profile.user.user_email
- this.responses = []
- this.user_type = type
- this.tags = profile.tags.filter(t => t.tag_category != 'reveal')
-
- // TODO: generalize this for multiple images, and languages
- this.profile_description = ''
- this.profile_media = []
- this.profile_languages = []
- this.profile_prefs = {}
-
- // TODO: Use reveal tags to add or remove information from profile!
- // TODO: ---
- // TODO: Use reveal tags to rebuild profile based on group/membership
- // TODO: and include for certain profiles
-
- this.reveal = profile.tags.filter(t => t.tag_category == 'reveal')
- // TODO: filter these correctly
- if (profile?.responses?.length && includeResponses) {
- // [] of all "profile" responses
- this.responses = profile.responses
- // image, language, duration, presence, blurb, urgency, role, pronouns, distance
- const prefs = [
- 'zipcode',
- 'duration',
- 'presence',
- 'urgency',
- 'pronouns',
- 'distance',
- ]
- const prefsKeys = config.prefKeys
- prefs.forEach((pref, i) => {
- this.profile_prefs[pref] = this.responses.find(
- r => r.response_key_id === prefsKeys[i],
- )
- })
- this.profile_description = this.responses.find(
- r => r.response_key_id === config.blurbKey,
- ).val
- this.profile_media = this.responses
- .filter(r => r.response_key_id === config.mediaKey)
- .map(r => r.val)
- this.profile_languages = this.responses
- .filter(r => r.response_key_id === config.langKey)
- .map(r => r.val)
- }
- }
- }
- const _makeCompleteProfile = (
- profileEntry,
- type,
- tagLookup,
- includeResponses,
- ) => {
- profileEntry.tags = profileEntry.tags.map(tag => tagLookup[tag.tag_id])
- return new CompleteProfile(profileEntry, includeResponses, type)
- }
-
- const makeOrderedCompleteProfiles = (
- orderedProfileIds,
- profilesEntries,
- type,
- includeResponses,
- tagLookup,
- ) => {
- const completeProfiles = []
- orderedProfileIds.forEach(pid => {
- profilesEntries.forEach(entry => {
- if (entry.profile_id != pid) return
- completeProfiles.push(
- _makeCompleteProfile(entry, type, tagLookup, includeResponses),
- )
- })
- })
- return completeProfiles
- }
- const makeCompleteFromProfileEntries = (profilesEntries, type, tagLookup) =>
- profilesEntries.map(entry => _makeCompleteProfile(entry, type, tagLookup))
-
- module.exports = {
- CompleteProfile,
- makeOrderedCompleteProfiles,
- makeCompleteFromProfileEntries,
- }
|