<commit_before>var express = require('express');
var router = express.Router();

router.get('/', global.apiCall, function(req, res, next) {
	res.json({
		status: "ok",
		version: "1"
	});
});

router.get('/announcements/get/:date', global.apiCall, function(req, res, next) {
	if (req.params.date == undefined) {
		res.json({
			status: "error",
			error: "Missing or invalid date parameter!"
		});
		return;
	}
	global.knex.select('*').from('planner_announcements').limit(1).where({
		date: req.params.date
	}).then(function (data) {
		if (data.length == 0) {
			res.json({
				status: "ok",
				announcement: null
			});
		} else {
			res.json({
				status: "ok",
				announcement: data[0]
			});
		}
	}).catch(function(error) {
		console.error("DB ERROR!");
		console.error(error);
		res.json({
			status: "error",
			error: "Database error"
		});
	});
});

router.get('/fridays/get/:date', global.apiCall, function(req, res, next) {
	if (req.params.date == undefined) {
		res.json({
			status: "error",
			error: "Missing or invalid date parameter!"
		});
		return;
	}
	global.knex.select('*').from('planner_fridays').limit(1).where({
		date: req.params.date
	}).then(function (data) {
		if (data.length == 0) {
			res.json({
				status: "ok",
				friday: null
			});
		} else {
			res.json({
				status: "ok",
				friday: data[0]
			});
		}
	}).catch(function(error) {
		console.error("DB ERROR!");
		console.error(error);
		res.json({
			status: "error",
			error: "Database error"
		});
	});
});

router.get('/events/get/:date/:section_index', global.apiCall, global.requireUser, global.getUserRecord, function(req, res, next) {
	if (req.params.date == undefined) {
		res.json({
			status: "error",
			error: "Missing or invalid date parameter!"
		});
		return;
	}
	if (req.params.section_index == undefined || parseInt(req.params.section_index) == NaN) {
		res.json({
			status: "error",
			error: "Missing or invalid section index parameter!"
		});
		return;
	}
	knex("planner_events").select("*").where({
		userId: res.locals.user.id,
		date: req.params.date,
		sectionIndex: req.params.section_index
	}).then(function(obj) {
		res.json({
			status: "ok",
			date: req.params.date,
			events: obj
		});
	}).catch(function() {
		res.json({
			status: "error",
			date: req.params.date,
			error: "Unknown database error"
		});
	});
});

router.get('/events/getWeek/:date/:section_index', global.apiCall, global.requireUser, global.getUserRecord, function(req, res, next) {
	if (req.params.date == undefined) {
		res.json({
			status: "error",
			error: "Missing or invalid date parameter!"
		});
		return;
	}
	if (req.params.section_index == undefined || parseInt(req.params.section_index) == NaN) {
		res.json({
			status: "error",
			error: "Missing or invalid section index parameter!"
		});
		return;
	}
	var endOfWeek = new Date(req.params.date);
	endOfWeek.setDate(endOfWeek.getDate() + 7);
	knex("planner_events").select("*").where({
		userId: res.locals.user.id,
		sectionIndex: req.params.section_index
	}).andWhere("date", ">=", req.params.date).andWhere("date", "<", endOfWeek).then(function(obj) {
		res.json({
			status: "ok",
			startDate: req.params.date,
			events: obj
		});
	}).catch(function() {
		res.json({
			status: "error",
			startDate: req.params.date,
			error: "Unknown database error"
		});
	});
});

router.post('/events/post/', global.apiCall, global.requireUser, global.getUserRecord, function(req, res, next) {
	if (req.body.date == undefined) {
		res.json({
			status: "error",
			error: "Missing or invalid date parameter!"
		});
		return;
	}
	if (req.body.subjectIndex == undefined || parseInt(req.body.subjectIndex) == NaN) {
		res.json({
			status: "error",<commit_msg>Work on #229<commit_after>var express = require('express');
var router = express.Router();

router.get('/', global.apiCall, function(req, res, next) {
	res.json({
		status: "ok",
		version: "1"
	});
});

router.get('/announcements/get/:date', global.apiCall, function(req, res, next) {
	if (req.params.date == undefined) {
		res.json({
			status: "error",
			error: "Missing or invalid date parameter!"
		});
		return;
	}
	global.knex.select('*').from('planner_announcements').limit(1).where({
		date: req.params.date
	}).then(function (data) {
		if (data.length == 0) {
			res.json({
				status: "ok",
				announcement: null
			});
		} else {
			res.json({
				status: "ok",
				announcement: data[0]
			});
		}
	}).catch(function(error) {
		console.error("DB ERROR!");
		console.error(error);
		res.json({
			status: "error",
			error: "Database error"
		});
	});
});

router.get('/fridays/get/:date', global.apiCall, function(req, res, next) {
	if (req.params.date == undefined) {
		res.json({
			status: "error",
			error: "Missing or invalid date parameter!"
		});
		return;
	}
	global.knex.select('*').from('planner_fridays').limit(1).where({
		date: req.params.date
	}).then(function (data) {
		if (data.length == 0) {
			res.json({
				status: "ok",
				friday: null
			});
		} else {
			res.json({
				status: "ok",
				friday: data[0]
			});
		}
	}).catch(function(error) {
		console.error("DB ERROR!");
		console.error(error);
		res.json({
			status: "error",
			error: "Database error"
		});
	});
});

router.get('/events/get/:date/:section_index', global.apiCall, global.requireUser, global.getUserRecord, function(req, res, next) {
	if (req.params.date == undefined) {
		res.json({
			status: "error",
			error: "Missing or invalid date parameter!"
		});
		return;
	}
	if (req.params.section_index == undefined || parseInt(req.params.section_index) == NaN) {
		res.json({
			status: "error",
			error: "Missing or invalid section index parameter!"
		});
		return;
	}
	knex("planner_events").select("*").where({
		userId: res.locals.user.id,
		date: req.params.date,
		sectionIndex: req.params.section_index
	}).then(function(obj) {
		res.json({
			status: "ok",
			date: req.params.date,
			events: obj
		});
	}).catch(function() {
		res.json({
			status: "error",
			date: req.params.date,
			error: "Unknown database error"
		});
	});
});

router.get('/events/getWeek/:date/:section_index', global.apiCall, global.requireUser, global.getUserRecord, function(req, res, next) {
	if (req.params.date == undefined) {
		res.json({
			status: "error",
			error: "Missing or invalid date parameter!"
		});
		return;
	}
	if (req.params.section_index == undefined || parseInt(req.params.section_index) == NaN) {
		res.json({
			status: "error",
			error: "Missing or invalid section index parameter!"
		});
		return;
	}
	var endOfWeek = new Date(req.params.date);
	endOfWeek.setDate(endOfWeek.getDate() + 7);
	knex("planner_events").select("*").where({
		userId: res.locals.user.id,
		sectionIndex: req.params.section_index
	}).andWhere("date", ">=", req.params.date).andWhere("date", "<", endOfWeek).then(function(obj) {
		res.json({
			status: "ok",
			startDate: req.params.date,
			events: obj
		});
	}).catch(function() {
		res.json({
			status: "error",
			startDate: req.params.date,
			error: "Unknown database error"
		});
	});
});

router.get('/events/getWholeWeek/:date', global.apiCall, global.requireUser, global.getUserRecord, function(req, res, next) {
	if (req.params.date == undefined) {
		res.json({
			status: "error",
			error: "Missing or invalid date parameter!"
		});
		return;
	}
	var endOfWeek = new Date(req.params.date);
	endOfWeek.setDate(endOfWeek.getDate() + 7);
	knex("planner_events").select("*").where({
		userId: res.locals.user.id
	}).andWhere("date", ">=", req.params.date).andWhere("date", "<", endOfWeek).then(function(obj) {
		res.json({
			status: "ok",
			startDate: req.params.date,
			events: obj
		});
	}).catch(function() {
		res.json({
			status: "error",
			startDate: req.params.date,
			error: "Unknown database error"
		});
	});
});

router.post('/events/post/', global.apiCall, global.requireUser, global.getUserRecord, function(req, res, next) {
	if (req.body.date == undefined) {
		res.json({
			status: "error",
			error: "Missing or invalid date parameter!"
		});
		return;
	}
	if (req.body.subjectIndex == undefined || parseInt(req.body.subjectIndex) == NaN) {
		res.json({
			status: "error",
{'fraction_non_alphanumeric': 0.19459062538245012, 'fraction_numerical': 0.0024476808224207563, 'mean_word_length': 3.7594641817122887, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5862015', 'n_tokens_mistral': 3239, 'n_tokens_neox': 2912, 'n_words': 582}