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', 'role', '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, }