mirror of
https://github.com/Karaka-Management/jsOMS.git
synced 2026-01-10 17:38:41 +00:00
54 lines
943 B
JavaScript
54 lines
943 B
JavaScript
/**
|
|
* Response manager class.
|
|
*
|
|
* Used for auto handling different responses.
|
|
*
|
|
* @copyright Dennis Eichhorn
|
|
* @license OMS License 2.2
|
|
* @version 1.0.0
|
|
* @since 1.0.0
|
|
*/
|
|
export class Response
|
|
{
|
|
/**
|
|
* @constructor
|
|
*
|
|
* @param {Object} data Response data
|
|
*
|
|
* @since 1.0.0
|
|
*/
|
|
constructor (data = {})
|
|
{
|
|
/** @type {Object} responses */
|
|
this.responses = data;
|
|
};
|
|
|
|
/**
|
|
* Get response by id.
|
|
*
|
|
* @param {null|string} [id] Response id
|
|
*
|
|
* @return {any}
|
|
*
|
|
* @since 1.0.0
|
|
*/
|
|
get (id = null)
|
|
{
|
|
return id === null
|
|
? this.responses
|
|
: (typeof this.responses[id] === 'undefined' ? null : this.responses[id]);
|
|
};
|
|
|
|
/**
|
|
* Count the amount of responses.
|
|
*
|
|
* @return {number}
|
|
*
|
|
* @since 1.0.0
|
|
*/
|
|
count ()
|
|
{
|
|
return this.responses.length;
|
|
};
|
|
};
|