cofounderella/lib/models/user_profile.dart

98 lines
3.1 KiB
Dart

import 'package:cloud_firestore/cloud_firestore.dart';
import '../constants.dart';
import '../enumerations.dart';
import '../services/user_service.dart';
import 'language.dart';
import 'location.dart';
class UserProfile {
final String id;
final String uid;
final String email;
String name;
final String firstName;
final String lastName;
String? profilePictureUrl;
String? bio;
Gender? gender;
int? born;
RiskTolerance risk;
AvailabilityOption availability;
CultureOption culture;
CommunicationPreference communication;
List<SkillOption> skills;
List<SkillOption> skillsSought;
List<VisionOption> visions;
List<WorkValueOption> workValues;
List<Language> languages;
Map<String, MyLocation?> locations;
UserProfile({
required this.id,
required this.uid,
required this.email,
required this.name,
required this.firstName,
required this.lastName,
this.profilePictureUrl,
this.bio,
this.gender,
this.born,
required this.risk,
required this.availability,
required this.culture,
required this.communication,
required this.skills,
required this.skillsSought,
required this.visions,
required this.workValues,
required this.languages,
required this.locations,
});
factory UserProfile.fromDocument(DocumentSnapshot doc) {
Map<String, dynamic> data = doc.data() as Map<String, dynamic>;
List<SkillOption> skillsOffered = UserService.convertSkillStringToEnum(
data[Constants.dbFieldUsersSkills]);
List<SkillOption> skillsSought = UserService.convertSkillStringToEnum(
data[Constants.dbFieldUsersSkillsSought]);
List<VisionOption> visions = UserService.convertVisionStringToEnum(
data[Constants.dbFieldUsersVisions]);
List<WorkValueOption> works = UserService.convertWorkValuesStringToEnum(
data[Constants.dbFieldUsersWorkValues]);
RiskTolerance risk =
RiskTolerance.fromString(data[Constants.dbFieldUsersRiskTolerance]);
AvailabilityOption availability =
AvailabilityOption.fromString(data[Constants.dbFieldUsersAvailability]);
CultureOption culture =
CultureOption.fromString(data[Constants.dbFieldUsersCorpCulture]);
CommunicationPreference communication = CommunicationPreference.fromString(
data[Constants.dbFieldUsersCommunication]);
return UserProfile(
id: doc.id,
uid: data[Constants.dbFieldUsersID] ?? '',
email: data[Constants.dbFieldUsersEmail] ?? '',
name: data[Constants.dbFieldUsersName] ?? '',
firstName: data[Constants.dbFieldUsersFirstName] ?? '',
lastName: data[Constants.dbFieldUsersLastName] ?? '',
skills: skillsOffered,
skillsSought: skillsSought,
visions: visions,
risk: risk,
availability: availability,
culture: culture,
communication: communication,
workValues: works,
profilePictureUrl: data[Constants.dbFieldUsersProfilePic],
bio: data[Constants.dbFieldUsersBio],
gender: Gender.values[data[Constants.dbFieldUsersGender] ?? 0],
born: data[Constants.dbFieldUsersYearBorn],
languages: [],
locations: {},
);
}
}