src/models/user/Session.js
/**
* Model representing a session.
*/
class SessionModel {
/**
* @param {Object} response - JSON formatted response of a session.
* @param {Number} response.id - The session ID value
* @param {String} response.sign_in_count - Number of sign ins
* @param {String} response.last_sign_in_at - Date in which the session was last signed in
* @param {String} response.failed_attempts - Number of failed attempts
* @param {String} response.locked_at - Date in which the session was locked
* @param {String} response.username - User name
* @param {String} response.email - The email address of the session
* @param {String} response.authentication_token - Current authentication token
* @param {String} response.confirmed_at - Date in which the session was confirmed
* @param {String} response.invitation_sent_at - Date in which the invitation was sent
* @param {String} response.invitation_accepted_at - Date in which the invitation was accepted
* @param {String} response.invitation_due_at - Date in which the invitation is going to expire
* @param {String} response.password_changed_at - Date in which the password was changed
* @param {String} response.disabled_at - Date in which the session was disabled
*/
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.signInCount = attributes.sign_in_count;
/** @type {String} */
this.lastSignInAt = attributes.last_sign_in_at;
/** @type {String} */
this.failedAttempts = attributes.failed_attempts;
/** @type {String} */
this.lockedAt = attributes.locked_at;
/** @type {String} */
this.username = attributes.username;
/** @type {String} */
this.email = attributes.email;
/** @type {String} */
this.authenticationToken = attributes.authentication_token;
/** @type {String} */
this.confirmedAt = attributes.confirmed_at;
/** @type {String} */
this.invitationSentAt = attributes.invitation_sent_at;
/** @type {String} */
this.invitationAcceptedAt = attributes.invitation_accepted_at;
/** @type {String} */
this.invitationDueAt = attributes.invitation_due_at;
/** @type {String} */
this.passwordChangedAt = attributes.password_changed_at;
/** @type {String} */
this.disabledAt = attributes.disabled_at;
}
}
export default SessionModel;