-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
121 lines (106 loc) · 2.31 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
const { google } = require("googleapis");
const moment = require('moment');
const {
loadAccess,
listEvents,
getParams,
generateSchedule,
clearAllEvents,
nthDayOfMonth,
} = require('./lib/index');
const PARENTS = 'Parents';
const MEL = 'Mel';
const JOHN = 'John';
const BACHELORS = 'Bachelors';
const onExistingNonMainItem = (existingName, { assignee, assignment }) => {
// If this person is on the main dish this day
if (existingName.includes('Main')) {
// Assign the parents to this item
return { assignment, assignee: PARENTS };
}
// Don't create an event
return null;
}
const DEFAULT_PARAMS = {
calendarId: '[email protected]',
start: '2020-02-02',
end: '2021-12-30',
intervalDays: 7,
onExisting: () => {
// Don't create another event
return null;
},
shouldSkipDate: (day) => {
const secondSunday = nthDayOfMonth(day, day.day(), 2),
fourthSunday = nthDayOfMonth(day, day.day(), 4);
return day.date() !== secondSunday.date() &&
day.date() !== fourthSunday.date();
},
};
const MAIN_PARAMS = {
...DEFAULT_PARAMS,
assignment: "Main",
assignees: [
PARENTS,
BACHELORS,
PARENTS,
MEL,
PARENTS,
JOHN,
],
};
const BREAD_PARAMS = {
...DEFAULT_PARAMS,
assignment: "Bread",
assignees: [
MEL,
JOHN,
BACHELORS,
],
onExisting: onExistingNonMainItem,
};
const VEGGIES_PARAMS = {
...DEFAULT_PARAMS,
assignment: "Veggies",
assignees: [
JOHN,
BACHELORS,
MEL,
],
onExisting: onExistingNonMainItem,
};
const DRINKS_PARAMS = {
...DEFAULT_PARAMS,
assignment: "Drinks/Dessert",
assignees: [
BACHELORS,
MEL,
JOHN,
],
onExisting: onExistingNonMainItem,
};
// Get access and go!
loadAccess(auth => {
const api = google.calendar({ version: "v3", auth });
getParams(api, DRINKS_PARAMS).then(params => {
try {
console.log(params)
if (false) {
console.log('Clearing all existing events')
clearAllEvents(api,
{
...params,
timeMin: moment(params.start).toISOString(),
}
);
return;
}
generateSchedule(api, params).then(() => {
process.exit();
});
} catch(e) {
console.log(`Encountered error: ${e}`)
process.exit(1);
}
});
});