diff --git a/src/helpers/rrule-options.js b/src/helpers/rrule-options.js index ae11427..d41052d 100644 --- a/src/helpers/rrule-options.js +++ b/src/helpers/rrule-options.js @@ -1,28 +1,17 @@ -const getFrequency = require('./frequency-converter'); const getDateTime = require('./datetime-helper'); -function generateRRuleOptions(node) { - const { freq, interval } = getFrequency(node.getValue('repeatFrequency')); - const properties = { - freq, - interval, - byDay: node.getValue('byDay'), - byMonth: node.getValue('byMonth'), - byMonthDay: node.getValue('byMonthDay'), - startDate: node.getValue('startDate'), - startTime: node.getValue('startTime'), - endDate: node.getValue('endDate'), - endTime: node.getValue('endTime'), - count: node.getValue('count'), - scheduleTimezone: node.getValue('scheduleTimezone'), - exceptDate: node.getValue('exceptDate'), - }; - +function generateRRuleOptions(properties) { const dtStart = getDateTime(properties.startDate, properties.startTime); const dtEnd = getDateTime(properties.endDate, properties.endTime); - const rruleOptions = { freq, interval }; // this is the only required one + const rruleOptions = {}; + if (typeof properties.freq !== 'undefined') { + rruleOptions.freq = properties.freq; + } + if (typeof properties.interval !== 'undefined') { + rruleOptions.interval = properties.interval; + } if (typeof dtStart !== 'undefined') { rruleOptions.dtstart = dtStart; } @@ -44,7 +33,7 @@ function generateRRuleOptions(node) { if (typeof properties.scheduleTimezone !== 'undefined') { rruleOptions.tzid = properties.scheduleTimezone; } - return { rruleOptions, properties }; + return rruleOptions; } module.exports = generateRRuleOptions; diff --git a/src/helpers/schedule-properties.js b/src/helpers/schedule-properties.js new file mode 100644 index 0000000..f732e2e --- /dev/null +++ b/src/helpers/schedule-properties.js @@ -0,0 +1,22 @@ +const getFrequency = require('./frequency-converter'); + +function getScheduleProperties(node) { + const { freq, interval } = getFrequency(node.getValue('repeatFrequency')); + const properties = { + freq, + interval, + byDay: node.getValue('byDay'), + byMonth: node.getValue('byMonth'), + byMonthDay: node.getValue('byMonthDay'), + startDate: node.getValue('startDate'), + startTime: node.getValue('startTime'), + endDate: node.getValue('endDate'), + endTime: node.getValue('endTime'), + count: node.getValue('count'), + scheduleTimezone: node.getValue('scheduleTimezone'), + exceptDate: node.getValue('exceptDate'), + }; + return properties; +} + +module.exports = getScheduleProperties; diff --git a/src/rules/data-quality/schedule-contains-recurrence-data-rule.js b/src/rules/data-quality/schedule-contains-recurrence-data-rule.js index a72500f..8e1a431 100644 --- a/src/rules/data-quality/schedule-contains-recurrence-data-rule.js +++ b/src/rules/data-quality/schedule-contains-recurrence-data-rule.js @@ -1,6 +1,7 @@ const { RRule } = require('rrule'); const Rule = require('../rule'); const generateRRuleOptions = require('../../helpers/rrule-options'); +const getScheduleProperties = require('../../helpers/schedule-properties'); const ValidationErrorType = require('../../errors/validation-error-type'); const ValidationErrorCategory = require('../../errors/validation-error-category'); const ValidationErrorSeverity = require('../../errors/validation-error-severity'); @@ -48,7 +49,8 @@ module.exports = class ValidRecurrenceRule extends Rule { validateModel(node) { const errors = []; - const { rruleOptions, properties } = generateRRuleOptions(node); + const properties = getScheduleProperties(node); + const rruleOptions = generateRRuleOptions(properties); if (typeof properties.startDate === 'undefined' || typeof properties.startTime === 'undefined' diff --git a/src/rules/data-quality/schedule-exceptdates-match-recurrence-dates.js b/src/rules/data-quality/schedule-exceptdates-match-recurrence-dates.js index eedff02..0d08742 100644 --- a/src/rules/data-quality/schedule-exceptdates-match-recurrence-dates.js +++ b/src/rules/data-quality/schedule-exceptdates-match-recurrence-dates.js @@ -4,6 +4,7 @@ const generateRRuleOptions = require('../../helpers/rrule-options'); const ValidationErrorType = require('../../errors/validation-error-type'); const ValidationErrorCategory = require('../../errors/validation-error-category'); const ValidationErrorSeverity = require('../../errors/validation-error-severity'); +const getScheduleProperties = require('../../helpers/schedule-properties'); module.exports = class ExceptDatesAreInSchedule extends Rule { constructor(options) { @@ -37,7 +38,8 @@ module.exports = class ExceptDatesAreInSchedule extends Rule { validateModel(node) { const errors = []; - const { rruleOptions, properties } = generateRRuleOptions(node); + const properties = getScheduleProperties(node); + const rruleOptions = generateRRuleOptions(properties); if (typeof properties.exceptDate === 'undefined') { return [];