function scheduleAllNotifications() {
	// make request to letter day API to get letter and X Block time
	request(sys.LETTER_DAY_ENDPOINT, function(err, response, body) {
		// if no error making request
		if (!err) {
			// parse string to object
			var res = JSON.parse(body);

			// if no letter day error
			if (!res.err) {
				// get letter and rotation info
				var letter = res.data.letter;
				var rotation = res.data.rotation;
				var XBlock;

				// if event schedule available
				if (res.data.schedule) {
					// find start time for X Block today
					for (var i = 0; i < res.data.schedule.length; i++) {
						// if X Block event found
						if (res.data.schedule[i].name == "X Block") {
							XBlock = moment(res.data.schedule[i].start);
							break;
						}
					}
				}

				// get static email & SMS notification times for today
				var emailNotifs = parseStaticTimes(sys.STATIC_EMAIL_NOTS);
				var smsNotifs = parseStaticTimes(sys.STATIC_SMS_NOTS);

				// if X Block time successfully found & parsed
				if (XBlock && XBlock.isValid()) {
					// get notification times relative to X Block, add to total notifications
					emailNotifs.push.apply(emailNotifs, parsePreXTimes(sys.PRE_X_EMAIL_NOTS, XBlock));
					smsNotifs.push.apply(smsNotifs, parsePreXTimes(sys.PRE_X_SMS_NOTS, XBlock));

					// get current letter day UID by name
					db.getLetterUIDByLetter(letter, function(err, uid) {
						if (!err) {
							// get all TAs who have hours today
							db.getTAsAssignedToLetter(uid, function(err, assignedTAs) {
								if (!err) {
									var ta;

									// construct TA object for each TA on hours today, use to schedule calls to notification functions
									for (var i = 0; i < assignedTAs.length; i++) {
										// construct new TA object, to have access to functions that will use this TA's contacts
										ta = new TA(assignedTAs[i].name, assignedTAs[i].phone, assignedTAs[i].email, XBlock);

										// log who we're scheduling for
										if (sys.LOGGING) console.log("Scheduling notifications for " + ta.name + " (" + assignedTAs[i].uid + ")...");

										// schedule an email notification for this TA at each specificed email notification time
										for (var k = 0; k < emailNotifs.length; k++) {
											schedule.scheduleJob(emailNotifs[k].toDate(), ta.notifyEmail);

											// log email scheduling
											if (sys.LOGGING) console.log("Scheduling email for " + ta.email + " at " + emailNotifs[k].format("YYYY-MM-DD hh:mm A"));
										}

										// schedule an SMS notification for this TA at each specified SMS notification time
										for (var k = 0; k < smsNotifs.length; k++) {
											schedule.scheduleJob(smsNotifs[k].toDate(), ta.notifySMS);

											// log SMS scheduling
											if (sys.LOGGING) console.log("Scheduling SMS for " + ta.phone + " at " + smsNotifs[k].format("YYYY-MM-DD hh:mm A"));
										}
									}
								} else {
									// log error
									console.log(err || "Unable to determine which TA's have hours today");
								}
							});
						} else {
							// log error
							console.log(err || "Unable to determine today's letter day");
						}
					});
				}
			} else {
				// log error
				console.log(res.err);
			}
		} else {
			// log error
			console.log(err);
		}
	});
}
// schedule all notifications for today's TAs
schedule all notifications for today's TAs
schedule all notifications for today ' s TAs
function scheduleAllNotifications() {
	request(sys.LETTER_DAY_ENDPOINT, function(err, response, body) {
		if (!err) {
			var res = JSON.parse(body);
			if (!res.err) {
				var letter = res.data.letter;
				var rotation = res.data.rotation;
				var XBlock;
				if (res.data.schedule) {
					for (var i = 0; i < res.data.schedule.length; i++) {
						if (res.data.schedule[i].name == "X Block") {
							XBlock = moment(res.data.schedule[i].start);
							break;
						}
					}
				}
				var emailNotifs = parseStaticTimes(sys.STATIC_EMAIL_NOTS);
				var smsNotifs = parseStaticTimes(sys.STATIC_SMS_NOTS);
				if (XBlock && XBlock.isValid()) {
					emailNotifs.push.apply(emailNotifs, parsePreXTimes(sys.PRE_X_EMAIL_NOTS, XBlock));
					smsNotifs.push.apply(smsNotifs, parsePreXTimes(sys.PRE_X_SMS_NOTS, XBlock));
					db.getLetterUIDByLetter(letter, function(err, uid) {
						if (!err) {
							db.getTAsAssignedToLetter(uid, function(err, assignedTAs) {
								if (!err) {
									var ta;
									for (var i = 0; i < assignedTAs.length; i++) {
										ta = new TA(assignedTAs[i].name, assignedTAs[i].phone, assignedTAs[i].email, XBlock);
										if (sys.LOGGING) console.log("Scheduling notifications for " + ta.name + " (" + assignedTAs[i].uid + ")...");
										for (var k = 0; k < emailNotifs.length; k++) {
											schedule.scheduleJob(emailNotifs[k].toDate(), ta.notifyEmail);
											if (sys.LOGGING) console.log("Scheduling email for " + ta.email + " at " + emailNotifs[k].format("YYYY-MM-DD hh:mm A"));
										}
										for (var k = 0; k < smsNotifs.length; k++) {
											schedule.scheduleJob(smsNotifs[k].toDate(), ta.notifySMS);
											if (sys.LOGGING) console.log("Scheduling SMS for " + ta.phone + " at " + smsNotifs[k].format("YYYY-MM-DD hh:mm A"));
										}
									}
								} else {
									console.log(err || "Unable to determine which TA's have hours today");
								}
							});
						} else {
							console.log(err || "Unable to determine today's letter day");
						}
					});
				}
			} else {
				console.log(res.err);
			}
		} else {
			console.log(err);
		}
	});
}
function scheduleAllNotifications ( ) { request ( sys . LETTER_DAY_ENDPOINT , function ( err , response , body ) { if ( ! err ) { var res = JSON . parse ( body ) ; if ( ! res . err ) { var letter = res . data . letter ; var rotation = res . data . rotation ; var XBlock ; if ( res . data . schedule ) { for ( var i = 0 ; i < res . data . schedule . length ; i ++ ) { if ( res . data . schedule [ i ] . name == "X Block" ) { XBlock = moment ( res . data . schedule [ i ] . start ) ; break ; } } } var emailNotifs = parseStaticTimes ( sys . STATIC_EMAIL_NOTS ) ; var smsNotifs = parseStaticTimes ( sys . STATIC_SMS_NOTS ) ; if ( XBlock && XBlock . isValid ( ) ) { emailNotifs . push . apply ( emailNotifs , parsePreXTimes ( sys . PRE_X_EMAIL_NOTS , XBlock ) ) ; smsNotifs . push . apply ( smsNotifs , parsePreXTimes ( sys . PRE_X_SMS_NOTS , XBlock ) ) ; db . getLetterUIDByLetter ( letter , function ( err , uid ) { if ( ! err ) { db . getTAsAssignedToLetter ( uid , function ( err , assignedTAs ) { if ( ! err ) { var ta ; for ( var i = 0 ; i < assignedTAs . length ; i ++ ) { ta = new TA ( assignedTAs [ i ] . name , assignedTAs [ i ] . phone , assignedTAs [ i ] . email , XBlock ) ; if ( sys . LOGGING ) console . log ( "Scheduling notifications for " + ta . name + " (" + assignedTAs [ i ] . uid + ")..." ) ; for ( var k = 0 ; k < emailNotifs . length ; k ++ ) { schedule . scheduleJob ( emailNotifs [ k ] . toDate ( ) , ta . notifyEmail ) ; if ( sys . LOGGING ) console . log ( "Scheduling email for " + ta . email + " at " + emailNotifs [ k ] . format ( "YYYY-MM-DD hh:mm A" ) ) ; } for ( var k = 0 ; k < smsNotifs . length ; k ++ ) { schedule . scheduleJob ( smsNotifs [ k ] . toDate ( ) , ta . notifySMS ) ; if ( sys . LOGGING ) console . log ( "Scheduling SMS for " + ta . phone + " at " + smsNotifs [ k ] . format ( "YYYY-MM-DD hh:mm A" ) ) ; } } } else { console . log ( err || "Unable to determine which TA's have hours today" ) ; } } ) ; } else { console . log ( err || "Unable to determine today's letter day" ) ; } } ) ; } } else { console . log ( res . err ) ; } } else { console . log ( err ) ; } } ) ; }
schedule all notifications for today's TAs
schedule all notifications for today ' s TAs
// make request to letter day API to get letter and X Block time // if no error making request // parse string to object // if no letter day error // get letter and rotation info // if event schedule available // find start time for X Block today // if X Block event found // get static email & SMS notification times for today // if X Block time successfully found & parsed // get notification times relative to X Block, add to total notifications // get current letter day UID by name // get all TAs who have hours today // construct TA object for each TA on hours today, use to schedule calls to notification functions // construct new TA object, to have access to functions that will use this TA's contacts // log who we're scheduling for // schedule an email notification for this TA at each specificed email notification time // log email scheduling // schedule an SMS notification for this TA at each specified SMS notification time // log SMS scheduling // log error // log error // log error // log error