Skip to content

Commit

Permalink
Eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
kennsippell committed Oct 3, 2023
1 parent 0521647 commit 8213dd4
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 23 deletions.
4 changes: 2 additions & 2 deletions src/nools/definition-preparation.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const Luxon = require('luxon');
const luxon = require('luxon');

/*
Declarative tasks and targets (the elements exported by partner task.js and target.js files), are complex objects containing functions.
Expand All @@ -18,7 +18,7 @@ function bindAllFunctionsToContext(obj, context) {
var key = keys[i];
switch(typeof obj[key]) {
case 'object':
const isLuxon = Luxon.Duration.isDuration(obj[key]) || Luxon.DateTime.isDateTime(obj[key]);
var isLuxon = luxon.Duration.isDuration(obj[key]) || luxon.DateTime.isDateTime(obj[key]);
if (!isLuxon) {
bindAllFunctionsToContext(obj[key], context);
}
Expand Down
37 changes: 18 additions & 19 deletions src/nools/task-emitter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const prepareDefinition = require('./definition-preparation');
const taskDefaults = require('./task-defaults');
const emitRecurringEvents = require('./task-recurring');
const getRecurringTasks = require('./task-recurring');

function taskEmitter(taskDefinitions, c, Utils, Task, emit) {
if (!taskDefinitions) return;
Expand All @@ -25,8 +25,8 @@ function taskEmitter(taskDefinitions, c, Utils, Task, emit) {
switch (taskDefinition.appliesTo) {
case 'reports':
case 'scheduled_tasks':
for (let idx2=0; idx2<c.reports.length; ++idx2) {
emitterContext.r = c.reports[idx2];
for (const report of c.reports) {
emitterContext.r = report;
emitTaskDefinition(emitterContext);
}
break;
Expand Down Expand Up @@ -97,20 +97,19 @@ function emitTaskDefinition(emitterContext) {
}

function emitForEvents(emitterContext, scheduledTaskIdx) {
let partialEmissions;

let emissionInfo;
if (Array.isArray(taskDefinition.events)) {
partialEmissions = emitEventsArray(emitterContext, scheduledTaskIdx);
emissionInfo = emitEventsArray(emitterContext, scheduledTaskIdx);
} else {
if (scheduledTaskIdx) {
throw 'not supported';
throw Error('appliesTo: "scheduled_tasks" is not supported with recurring tasks');
}

partialEmissions = emitRecurringEvents(emitterContext);
emissionInfo = getRecurringTasks(emitterContext);
}

partialEmissions.forEach(partialEmission => {
emitTaskEvent(emitterContext, partialEmission);
emissionInfo.forEach(emission => {
emitTaskEvent(emitterContext, emission);
});
}

Expand Down Expand Up @@ -149,22 +148,22 @@ function emitTaskDefinition(emitterContext) {
return result;
}

function emitTaskEvent(emitterContext, partialEmission, scheduledTaskIdx) {
function emitTaskEvent(emitterContext, emissionInfo, scheduledTaskIdx) {
const { taskDefinition, Utils, c, r, emit, Task } = emitterContext;

if (!partialEmission._id) {
throw 'partialEmission._id';
if (!emissionInfo._id) {
throw 'emissionInfo._id';
}

if (!partialEmission.date) {
throw 'partialEmission.date';
if (!emissionInfo.date) {
throw 'emissionInfo.date';
}

if (!partialEmission.event) {
throw 'partialEmission.event';
if (!emissionInfo.event) {
throw 'emissionInfo.event';
}

const { event, date: dueDate } = partialEmission;
const { event, date: dueDate } = emissionInfo;
if (!Utils.isTimely(dueDate, event)) {
return;
}
Expand Down Expand Up @@ -197,7 +196,7 @@ function emitTaskDefinition(emitterContext) {
defaultEmission.priorityLabel = priority.label;
}

const emission = Object.assign({}, defaultEmission, partialEmission);
const emission = Object.assign({}, defaultEmission, emissionInfo);
delete emission.event;
emit('task', new Task(emission));
}
Expand Down
4 changes: 2 additions & 2 deletions src/nools/task-recurring.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function getRecurringInterval(events) {
function getCriteriaInterval(recurringInterval, timelyInterval, events) {
const expandedTimelyInterval = Interval.fromDateTimes(
timelyInterval.start.plus({ days: -events.end || 0 }),
timelyInterval.end.plus({ days: events.start || 0 }),
timelyInterval.end.plus({ days: events.start || 0 })
);
return recurringInterval.intersection(expandedTimelyInterval);
}
Expand Down Expand Up @@ -100,7 +100,7 @@ function getIterationInterval(events, recurringInterval, criteriaInterval, perio

return Interval.fromDateTimes(
advanceDateTimeUsingPeriod(recurringInterval.start, startWithoutPeriod),
advanceDateTimeUsingPeriod(recurringInterval.end, endWithoutPeriod, false),
advanceDateTimeUsingPeriod(recurringInterval.end, endWithoutPeriod, false)
);
}

Expand Down

0 comments on commit 8213dd4

Please sign in to comment.