src/models/user/User.js
/**
* Model representing a user.
*/
class UserModel {
/**
* @param {Object} response - JSON formatted response of a user.
* @param {Number} response.id - The user ID value
* @param {String} response.account_name - Account name (usually a number)
* @param {String} response.anti_spam_accepted_at - Date when anti-spam policy was accepted by user.
* @param {String} response.created_at - Date when the user was created
* @param {Boolean} response.disabled - Whether or not the user account is disabled
* @param {String} response.disabled_at - Date when the user was disabled
* @param {String} response.email - The email address of the user
* @param {String} response.encryption_key - The encryption key for unlocking data
* @param {String} response.invitation_accepted_at - Date when the invitation was accepted
* @param {String} response.invitation_due_at - Date when the invitation is going to expire
* @param {String} response.invitation_sent_at - Date when the invitation was sent
* @param {String} response.password_expired_at - Date when the password expired
* @param {String} response.privacy_policy_accepted_at - Date when privacy policy was accepted by user.
* @param {String} response.role - Only from platform
* @param {String} response.terms_of_use_accepted_at - Date when terms of use were accepted by user.
* @param {String} response.updated_at - Date when the user was updated
* @param {String} response.uuid - The last used uuid for this mobile user
* @param {String} response.user - Only from platform, this is the email address
* @param {String} response.verified_at - Date when the user was verified
* @param {String} response.withdrawn_at - Date when the user was withdrawn
*/
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);
}
/** @type {String} */
this.accountName = attributes.account_name;
/** @type {String} */
this.antiSpamAcceptedAt = attributes.anti_spam_accepted_at;
/** @type {String} */
this.createdAt = attributes.created_at;
/** @type {Boolean} */
this.disabled = attributes.disabled;
/** @type {String} */
this.disabledAt = attributes.disabled_at;
/** @type {String} */
this.email = attributes.email;
/** @type {String} */
this.encryptionKey = attributes.encryption_key;
/** @type {String} */
this.guest = attributes.guest;
/** @type {String} */
this.invitationAcceptedAt = attributes.invitation_accepted_at;
/** @type {String} */
this.invitationDueAt = attributes.invitation_due_at;
/** @type {String} */
this.invitationSentAt = attributes.invitation_sent_at;
/** @type {String} */
this.passwordExpiredAt = attributes.password_expired_at;
/** @type {String} */
this.privacyPolicyAcceptedAt = attributes.privacy_policy_accepted_at;
/** @type {String} */
this.updatedAt = attributes.updated_at;
/** @type {String} */
this.uuid = attributes.uuid;
/** @type {String} */
this.termsOfUseAcceptedAt = attributes.terms_of_use_accepted_at;
/** @type {String} */
if (attributes.user) {
this.email = attributes.user;
}
/** @type {String} */
this.username = attributes.username;
/** @type {String} */
this.verifiedAt = attributes.verified_at;
/** @type {boolean} */
this.withdraw = attributes.withdraw;
/** @type {String} */
this.withdrawnAt = attributes.withdrawn_at;
// /** @type {String} */
// this.role = attributes.role;
/** @type {Boolean} */
this.enabled = attributes.enabled;
}
}
export default UserModel;