Skip to content

Commit c5418ff

Browse files
author
Jared Parnell
committed
helpers: Separate concerns between helper files
1 parent 88c39cb commit c5418ff

File tree

4 files changed

+37
-22
lines changed

4 files changed

+37
-22
lines changed

src/helpers/rrule-options.js

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,17 @@
1-
const getFrequency = require('./frequency-converter');
21
const getDateTime = require('./datetime-helper');
32

4-
function generateRRuleOptions(node) {
5-
const { freq, interval } = getFrequency(node.getValue('repeatFrequency'));
6-
const properties = {
7-
freq,
8-
interval,
9-
byDay: node.getValue('byDay'),
10-
byMonth: node.getValue('byMonth'),
11-
byMonthDay: node.getValue('byMonthDay'),
12-
startDate: node.getValue('startDate'),
13-
startTime: node.getValue('startTime'),
14-
endDate: node.getValue('endDate'),
15-
endTime: node.getValue('endTime'),
16-
count: node.getValue('count'),
17-
scheduleTimezone: node.getValue('scheduleTimezone'),
18-
exceptDate: node.getValue('exceptDate'),
19-
};
20-
3+
function generateRRuleOptions(properties) {
214
const dtStart = getDateTime(properties.startDate, properties.startTime);
225
const dtEnd = getDateTime(properties.endDate, properties.endTime);
236

24-
const rruleOptions = { freq, interval }; // this is the only required one
7+
const rruleOptions = {};
258

9+
if (typeof properties.freq !== 'undefined') {
10+
rruleOptions.freq = properties.freq;
11+
}
12+
if (typeof properties.interval !== 'undefined') {
13+
rruleOptions.interval = properties.interval;
14+
}
2615
if (typeof dtStart !== 'undefined') {
2716
rruleOptions.dtstart = dtStart;
2817
}
@@ -44,7 +33,7 @@ function generateRRuleOptions(node) {
4433
if (typeof properties.scheduleTimezone !== 'undefined') {
4534
rruleOptions.tzid = properties.scheduleTimezone;
4635
}
47-
return { rruleOptions, properties };
36+
return rruleOptions;
4837
}
4938

5039
module.exports = generateRRuleOptions;

src/helpers/schedule-properties.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
const getFrequency = require('./frequency-converter');
2+
3+
function getScheduleProperties(node) {
4+
const { freq, interval } = getFrequency(node.getValue('repeatFrequency'));
5+
const properties = {
6+
freq,
7+
interval,
8+
byDay: node.getValue('byDay'),
9+
byMonth: node.getValue('byMonth'),
10+
byMonthDay: node.getValue('byMonthDay'),
11+
startDate: node.getValue('startDate'),
12+
startTime: node.getValue('startTime'),
13+
endDate: node.getValue('endDate'),
14+
endTime: node.getValue('endTime'),
15+
count: node.getValue('count'),
16+
scheduleTimezone: node.getValue('scheduleTimezone'),
17+
exceptDate: node.getValue('exceptDate'),
18+
};
19+
return properties;
20+
}
21+
22+
module.exports = getScheduleProperties;

src/rules/data-quality/schedule-contains-recurrence-data-rule.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const { RRule } = require('rrule');
22
const Rule = require('../rule');
33
const generateRRuleOptions = require('../../helpers/rrule-options');
4+
const getScheduleProperties = require('../../helpers/schedule-properties');
45
const ValidationErrorType = require('../../errors/validation-error-type');
56
const ValidationErrorCategory = require('../../errors/validation-error-category');
67
const ValidationErrorSeverity = require('../../errors/validation-error-severity');
@@ -48,7 +49,8 @@ module.exports = class ValidRecurrenceRule extends Rule {
4849
validateModel(node) {
4950
const errors = [];
5051

51-
const { rruleOptions, properties } = generateRRuleOptions(node);
52+
const properties = getScheduleProperties(node);
53+
const rruleOptions = generateRRuleOptions(properties);
5254

5355
if (typeof properties.startDate === 'undefined'
5456
|| typeof properties.startTime === 'undefined'

src/rules/data-quality/schedule-exceptdates-match-recurrence-dates.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const generateRRuleOptions = require('../../helpers/rrule-options');
44
const ValidationErrorType = require('../../errors/validation-error-type');
55
const ValidationErrorCategory = require('../../errors/validation-error-category');
66
const ValidationErrorSeverity = require('../../errors/validation-error-severity');
7+
const getScheduleProperties = require('../../helpers/schedule-properties');
78

89
module.exports = class ExceptDatesAreInSchedule extends Rule {
910
constructor(options) {
@@ -37,7 +38,8 @@ module.exports = class ExceptDatesAreInSchedule extends Rule {
3738
validateModel(node) {
3839
const errors = [];
3940

40-
const { rruleOptions, properties } = generateRRuleOptions(node);
41+
const properties = getScheduleProperties(node);
42+
const rruleOptions = generateRRuleOptions(properties);
4143

4244
if (typeof properties.exceptDate === 'undefined') {
4345
return [];

0 commit comments

Comments
 (0)