src/models/reminder/Schedule.js
/**
* Model representing an Schedule.
*/
class ScheduleModel {
/**
* @param {Object} response - JSON formatted response of an schedule.
* @param {Number} response.id - The schedule id value
* @param {String} response.active_time_start - Active start time for the rule
* @param {String} response.active_time_end - Active end time for the rule
* @param {String} response.created_at - Date in which the schedule was created
* @param {String} response.days_of_week - Comma delimited list from 0 - 6 for days of week.
* @param {Boolean} response.enabled - Whether or not the schedule is enabled
* @param {String} response.end_date - Date in which the schedule ends
* @param {String} response.exception_days - Days that the rule should not apply, ie: 'holidays'
* @param {String} response.relative_schedule - In combination with the relative_unit, determines the schedule
* starting from the start date in which the scheduleable will occur. Example:
* relative_schedule = [1 ,5, 10], relative_unit = days means that day 1, day 5 and day 10 the
* scheduleable will be triggered (Comma delimited String)
* @param {String} response.relative_unit - Must be: 'days', 'weeks', or 'months'
* @param {Boolean} response.skip_exceptions - Whether or not the schedule has skip exceptions
* @param {String} response.start_date - Date in which the schedule starts
* @param {Number} response.start_date_offset - Number of units from the start_date
* @param {String} response.start_date_offset_unit - Unit used by start_date_offset, ie: 'day'
* @param {String} response.time - Time must be military format with dd:dd like "10:00"
* @param {String} response.timezone - Timezone like "UTC"
* @param {String} response.updated_at - Date in which the schedule was updated
*/
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.activeTimeStart = attributes.active_time_start;
/** @type {String} */
this.activeTimeEnd = attributes.active_time_end;
/** @type {String} */
this.createdAt = attributes.created_at;
/** @type {String} */
this.daysOfWeek = attributes.days_of_week;
/** @type {Boolean */
this.enabled = attributes.enabled;
/** @type {String} */
this.endDate = attributes.end_date;
/** @type {String} */
this.exceptionDays = attributes.exception_days;
/** @type {String} */
this.relativeSchedule = attributes.relative_schedule;
/** @type {String} */
this.relativeUnit = attributes.relative_unit;
/** @type {Boolean */
this.skipExceptions = attributes.skip_exceptions;
/** @type {String} */
this.startDate = attributes.start_date;
/** @type {Number} */
this.startDateOffset = attributes.start_date_offset;
/** @type {String} */
this.startDateOffsetUnit = attributes.start_date_offset_unit;
/** @type {String} */
this.time = attributes.time;
/** @type {String} */
this.timezone = attributes.timezone;
/** @type {String} */
this.updatedAt = attributes.updated_at;
}
}
export default ScheduleModel;