src/models/user/Profile.js
import { stringToCamel } from '../../utilities/FormatUtility';
/**
* Model representing a user profile.
*/
class ProfileModel {
/**
* @param {Object} response - JSON formatted response of a user profile.
* @param {String} response.username - The username of the profile
* @param {String} response.first_name - First name of the user
* @param {String} response.last_name - The last name of the user
* @param {Object} response.avatar - The avatar value of the profile
* @param {String} response.gender - The user's gender
* @param {Number} response.age - The age of the user
* @param {String} response.ethnicity - The user's ethnicity
* @param {String} response.zip_code - Zip code of the user
* @param {String} response.occupation - User's occupation
* @param {String} response.phone - Phone number of the user
* @param {String} response.city - The city portion of the user's address
* @param {String} response.dob - The user's date of birth
* @param {String} response.updated_at - The last time the user profile was updated
* @param {String} response.timezone - The timezone of the user profile
* @param {String} response.state - The state portion of the user's address
* @param {String} response.street - The street portion of the user's address
* @param {String} response.occupation - The user's occupation
* @param {String} response.middle_initial - The user's middle initial
* @param {Number} response.id - The profile ID value
* @param {String} response.created_at - The date that the profile was created on
* @param {Array} response.nodes - Node values of the profile
*/
constructor(response = {}) {
const _response = response.data || response; // if json api is passed in directly
const attributes = _response.attributes || _response; // if json api is passed in directly
if (_response.id) {
/** @type {Number} */
this.id = parseInt(_response.id, 10);
}
Object.keys(attributes).forEach((key) => {
if (['id', 'type'].indexOf(key) === -1) {
/** @type {Any} */
this[stringToCamel(key)] = attributes[key];
}
});
/** @type {Object} */
this.avatar = attributes.avatar;
/** @type {String} */
this.city = attributes.city;
/** @type {String} */
this.createdAt = attributes.created_at;
/** @type {String} */
this.dob = attributes.dob;
// /** @type {String} */
// this.email = attributes.email;
/** @type {String} */
this.ethnicity = attributes.ethnicity;
/** @type {String} */
this.firstName = attributes.first_name;
/** @type {String} */
this.gender = attributes.gender;
/** @type {String} */
this.lastName = attributes.last_name;
/** @type {String} */
this.middleInitial = attributes.middle_initial;
// /** @type {Array} - not documented */
// this.nodes = attributes.nodes;
/** @type {String} */
this.occupation = attributes.occupation;
/** @type {String} - not documented */
this.phone = attributes.phone;
/** @type {String} */
this.prefix = attributes.prefix;
// /** @type {Number} - not documented */
// this.profileableId = attributes.profileable_id;
// /** @type {String} - not documented */
// this.profileableType = attributes.profileable_type;
/** @type {String} - not documented */
this.state = attributes.state;
/** @type {String} */
this.street = attributes.street;
/** @type {String} */
this.suffix = attributes.suffix;
// /** @type {String} - not documented */
// this.tempEmail = attributes.temp_email;
/** @type {String} */
this.timezone = attributes.timezone;
/** @type {String} */
this.updatedAt = attributes.updated_at;
// /** @type {String} - not documented */
// this.userRole = attributes.user_role;
/** @type {String} */
this.username = attributes.username;
/** @type {String} */
this.zipCode = attributes.zip_code;
if (attributes.role) {
/** @type {String} - not documented */
this.role = attributes.role;
} else if (this.userRole && this.userRole.name) {
/** @type {String} - not documented */
this.role = this.userRole.name;
}
}
}
export default ProfileModel;