src/models/discuss/Comment.js
/**
* Model representing a comment.
*/
class CommentModel {
/**
* @param {Object} response - JSON formatted response of a comment
* @param {String} response.id - The comment id
* @param {Object} response.attributes - Attributes for a comment
* @param {String} response.attributes.body - The comment text
* @param {String} response.attributes.created_at - The creation timestamp
* @param {String} response.relations - The comment relationships
* @param {String} response.relations.author - The comment author
* @param {String} response.relations.author.id - The author's id
* @param {String} response.relations.author.email - The author's email
* @param {String} response.relations.author.username - The author's username
* @param {String} response.relations.author.user_role - The author's role
*/
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.body = attributes.body;
/** @type {String} */
this.createdAt = attributes.created_at;
/**
* @type {Object}
* @deprecated
*/
if (response.relations && response.relations.author) {
this.author = response.relations.author;
}
}
}
export default CommentModel;