src/models/user/Invitation.js
import { stringToCamel } from '../../utilities/FormatUtility';
import { fieldsToSnake } from '../../utilities/ClassUtility';
/**
* Model representing a User Invitation Model.
*/
class InvitationModel {
/**
* @param {Object} response - JSON formatted response of an invitation.
* @param {Number} response.id - The invitation id value
* @param {String} response.email - User email
* @param {String} response.first_name - User first name
* @param {String} response.last_name - User last name
* @param {String} response.phone - User phone number
* @param {String} response.suffix - User Suffix
* @param {String} response.dob - User date of birth
* @param {String} response.account_name - User account name [mobile users]
* @param {String} response.relationship - User relationship ('father', 'mother', etc) [mobile users]
*/
constructor(response = {}) {
const _response = response.data || response; // if json api is passed in directly
const attributes = fieldsToSnake(_response.attributes || _response); // if json api is passed in directly or camel format fields
if (_response.id) {
/** @type {Number} */
this.id = parseInt(_response.id, 10);
}
Object.keys(attributes).forEach((key) => {
if (['id', 'type', 'role', 'language', 'followed'].indexOf(key) === -1) {
/** @type {Any} */
this[stringToCamel(key)] = attributes[key];
}
});
/** @type {String} */
this.email = attributes.email;
/** @type {String} */
this.firstName = attributes.first_name;
/** @type {String} */
this.lastName = attributes.last_name;
/** @type {String} */
this.phone = attributes.phone;
/** @type {String} */
this.suffix = attributes.suffix;
/** @type {String} */
this.dob = attributes.dob;
/** @type {String} */
this.accountName = attributes.account_name;
/** @type {String} */
this.relationship = attributes.relationship;
}
}
export default InvitationModel;