<commit_before>exports.initialize = ({ auth, tasker, showModel, authController, respond }) => {
	// split and partly move to controller
	const ensureAuthenticated = (req, res, next) => {
		const token = auth.getAuthToken(req.headers);
		if (!token) {
			return respond.unauthorized(res);
		}

		const { decodedToken, tokenExpired } = auth.validateToken(token);

		if (decodedToken) {
			// TODO: change it!
			req.user = decodedToken.user;
			return next();
		}

		if (tokenExpired) {
			return respond.badRequest(res, 'Access token has expired');
		}

		return respond.internalError(res);
	};

	return [
		{
			endpoint: '/auth/login',
			method: 'post',
			action: (req, res) => {
				authController.login(req, res)
					.then((token) => {
						if (!token) {
							return respond.unauthorized(res);
						}
						respond.ok({ token });
					});
			},
		}, {
			endpoint: '/auth/logout',
			method: 'get',
			action: (req, res) => authController.logout(req, res),
		}, {
			endpoint: '/auth/signup',
			method: 'post',
			action: (req, res, next) => {
				authController.signup(req.body.email, req.body.password)
					.then(() => respond.ok(res))
					.catch(err => next(err));
			},
		}, {
			endpoint: '/api/shows',
			method: 'get',
			action: (req, res, next) => {
				showController.getShowsByFilter(req.query.genre, req.query.alphabet)
					.then(result => respond.ok(res, result))
					.catch(err => next(err));
			},
		}, {
			endpoint: '/api/shows/:id',
			method: 'get',
			action: (req, res, next) => {
				showController.getShow(req.params.id)
					.then(result => respond.ok(res, result))
					.catch(err => next(err));
			},
		}, {
			endpoint: '/api/shows',
			method: 'post',
			action: (req, res, next) => {<commit_msg>added a new route for FB authorization<commit_after>exports.initialize = ({ auth, tasker, showModel, authController, respond }) => {
	// split and partly move to controller
	const ensureAuthenticated = (req, res, next) => {
		const token = auth.getAuthToken(req.headers);
		if (!token) {
			return respond.unauthorized(res);
		}

		const { decodedToken, tokenExpired } = auth.validateToken(token);

		if (decodedToken) {
			// TODO: change it!
			req.user = decodedToken.user;
			return next();
		}

		if (tokenExpired) {
			return respond.badRequest(res, 'Access token has expired');
		}

		return respond.internalError(res);
	};

	return [
		{
			endpoint: '/auth/login',
			method: 'post',
			action: (req, res) => {
				authController.login(req, res)
					.then((token) => {
						if (!token) {
							return respond.unauthorized(res);
						}
						respond.ok({ token });
					});
			},
		}, {
			endpoint: '/auth/logout',
			method: 'get',
			action: (req, res) => authController.logout(req, res),
		}, {
			endpoint: '/auth/signup',
			method: 'post',
			action: (req, res, next) => {
				authController.signup(req.body.email, req.body.password)
					.then(() => respond.ok(res))
					.catch(err => next(err));
			},
		}, {
			endpoint: '/auth/facebook',
			method: 'post',
			action: (req, res, next) => {
				const { profile, signedRequest } = req.body;
				const [ signature, payload, ...rest ] = signedRequest.split('.');

				authController.fb(profile, signature, payload)
					.then((token) => respond.ok({ token }))
					.catch((error) => {
						if (error.invalidSignature) {
							return respond.badRequest('Invalid signature');
						}
						return next(error);
					});
			},
		}, {
			endpoint: '/api/shows',
			method: 'get',
			action: (req, res, next) => {
				showController.getShowsByFilter(req.query.genre, req.query.alphabet)
					.then(result => respond.ok(res, result))
					.catch(err => next(err));
			},
		}, {
			endpoint: '/api/shows/:id',
			method: 'get',
			action: (req, res, next) => {
				showController.getShow(req.params.id)
					.then(result => respond.ok(res, result))
					.catch(err => next(err));
			},
		}, {
			endpoint: '/api/shows',
			method: 'post',
			action: (req, res, next) => {
{'fraction_non_alphanumeric': 0.1824358329139406, 'fraction_numerical': 0.0, 'mean_word_length': 2.9239881539980255, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 36, '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': '452003', 'n_tokens_mistral': 1674, 'n_tokens_neox': 1338, 'n_words': 285}