src/models/version/Version.js
import { fieldsToCamel } from '../../utilities/ClassUtility';
/**
* Model representing an audit version.
*/
class VersionModel {
/**
* @param {Object} response - JSON formatted response of an audit version.
* @param {Number} response.id - The audit version ID value
* @param {Boolean} response.category - The category of the audit version.
* @param {String} response.created_at - The date when the audit version was created.
* @param {String} response.event - Event of the audit change. This can be 'create', 'update', or 'destroy'.
* @param {String} response.ip - Ip information associated with this audit version.
* @param {Object} response.original_object - Original object will be present if event is either 'destroy' or 'update'. This is the original object that was either destroyed or updated.
* @param {Object} response.object_changes - Object changes will appear if event is either 'create' or 'update'. This is an object with key/value information on attribute changes that were made.
* @param {Object} response.reason_for_changes - Object changes will appear if event is 'update'. This is an object with key/value information on reason for change.
* @param {String} response.user_agent - User agent associated with this audit version.
*/
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.category = attributes.category;
/** @type {String} */
this.createdAt = attributes.created_at;
/** @type {String} */
this.event = attributes.event;
/** @type {String} */
this.ip = attributes.ip;
/** @type {Object} */
this.originalObject = fieldsToCamel(attributes.original_object);
/** @type {Object} */
this.objectChanges = fieldsToCamel(attributes.object_changes); // if json api is passed in directly
/** @type {String} */
this.userAgent = attributes.user_agent;
/** @type {Object} */
this.reasonForChanges = fieldsToCamel(attributes.reason_for_changes);
}
}
export default VersionModel;