/** * */ class JobNotificationDTO { /** * * @param {any} json */ constructor (json) { this.json = json this.expression = Expression.fromRule(this) } /** * @type {string} */ get id () { return this.json.id } /** * @type {string} */ get rule () { return this.json.rule } set rule (s) { this.json.rule = s } /** * @type {string} */ get addressesString () { return this.json.addresses.map(a => a.address).join(',') } /** * @returns {boolean} */ isConditional () { return this.expression.type === 'CONDITIONAL' } } /** * */ class Expression { /** * * @param {JobNotificationDTO} notification * @returns {Expression} */ static fromRule (notification) { const type = notification.rule === '*' ? 'ALWAYS' : 'CONDITIONAL' let property let operator let value if (type === 'CONDITIONAL') { const parts = notification.rule.split(' ') property = parts[0] operator = parts[1] value = parts[2] } const expression = new Expression(type, property, operator, value) return expression } /** * @param {string} type * @param {string} [property] * @param {string} [operator] * @param {string} [value] */ constructor (type, property, operator, value) { this.type = type this.property = property this.operator = operator this.value = value } /** * * @returns {string} */ toRule () { if (this.type === 'ALWAYS') { return '*' } else { return `${this.property} ${this.operator} ${this.value}` } } } export default JobNotificationDTO