<commit_before>const createConsentFilterQuery = (...status) => {
	const currentDate = new Date();
	const secondConsentSwitchDate = new Date();
	secondConsentSwitchDate.setFullYear(currentDate.getFullYear() - 16); // TODO: get age from default.conf
	const firstConsentSwitchDate = new Date();
	firstConsentSwitchDate.setFullYear(currentDate.getFullYear() - 14);

	const requiredConsents = {
		privacyConsent: true,
		termsOfUseConsent: true,
	};

	const missingConsents = {
		$or: [
			{ privacyConsent: false },
			{ termsOfUseConsent: false },
		],
	};

	const orConditions = status.reduce((query, status) => {
		if (status === 'missing') {
			query.push({
				consent: {
					userConsent: missingConsents,
				},
				birthday: {
					$gte: secondConsentSwitchDate,
				},
			});
			query.push({
				consent: {
					parentConsents: missingConsents,
				},
				birthday: {
					$gt: firstConsentSwitchDate,
					$lte: secondConsentSwitchDate,
				},
			});
			query.push({
				consent: {
					parentConsents: missingConsents,
				},
				birthday: {
					$lt: firstConsentSwitchDate,
				},
			});
		} else if (status === 'parentAgree') {
			query.push({
				consent: {
					userConsent: missingConsents,
					parentConsents: requiredConsents,
				},
				birthday: {
					$gt: firstConsentSwitchDate,
					$lte: secondConsentSwitchDate,
				},
			});
		} else if (status === 'ok') {
			query.push({
				consent: {
					userConsent: requiredConsents,
				},
				birthday: {
					$gte: secondConsentSwitchDate,
				},
			});
			query.push({
				consent: {
					userConsent: requiredConsents,
					parentConsents: requiredConsents,
				},
				birthday: {
					$gt: firstConsentSwitchDate,
					$lte: secondConsentSwitchDate,
				},
			});
			query.push({
				consent: {
					parentConsents: requiredConsents,
				},
				birthday: {
					$lt: firstConsentSwitchDate,
				},
			});
		}
	}, []);

	return {
		$or: orConditions,
	};
};


const userToConsent = (user) => ({
	_id: user._id,
	userId: user._id,
	requiresParentConsent: user.requiresParentConsent,
	consentStatus: user.consentStatus,
	...user.consent,
});

const modifyDataForUserSchema = (data) => ({
	consent: {
		...data,
	},
});

module.exports = {
	createConsentFilterQuery,
	userToConsent,
	modifyDataForUserSchema,
};<commit_msg>fixed mongo query and add comments<commit_after>/**
 * Converts consentStatus to a filter condition for consent
 * @param  {...string} status
 */
const createConsentFilterQuery = (...status) => {
	const currentDate = new Date();
	const secondConsentSwitchDate = new Date();
	secondConsentSwitchDate.setFullYear(currentDate.getFullYear() - 16); // TODO: get age from default.conf
	const firstConsentSwitchDate = new Date();
	firstConsentSwitchDate.setFullYear(currentDate.getFullYear() - 14);


	const createRequiredConsents = (...persons) => persons.reduce((person, current) => {
		current[`consent.${person}.privacyConsent`] = true;
		current[`consent.${person}.termsOfUseConsent`] = true;

		return current;
	}, {});

	const createMissingConsents = (...persons) => persons.reduce((person, current) => {
		current.$or.push({ [`consent.${person}.privacyConsent`]: true });
		current.$or.push({ [`consent.${person}.termsOfUseConsent`]: true });

		return current;
	}, { $or: [] });


	const orConditions = status.reduce((query, stat) => {
		if (stat === 'missing') {
			query.push({
				...createMissingConsents('userConsent'),
				birthday: {
					$gte: secondConsentSwitchDate,
				},
			});
			query.push({
				...createMissingConsents('parentConsents'),
				birthday: {
					$gt: firstConsentSwitchDate,
					$lte: secondConsentSwitchDate,
				},
			});
			query.push({
				...createMissingConsents('parentConsents'),
				birthday: {
					$lt: firstConsentSwitchDate,
				},
			});
		} else if (stat === 'parentAgree') {
			query.push({
				...createRequiredConsents('parentConsents'),
				...createMissingConsents('userConsent'),
				birthday: {
					$gt: firstConsentSwitchDate,
					$lte: secondConsentSwitchDate,
				},
			});
		} else if (stat === 'ok') {
			query.push({
				...createRequiredConsents('userConsent'),
				birthday: {
					$gte: secondConsentSwitchDate,
				},
			});
			query.push({
				...createRequiredConsents('userConsent', 'parentConsents'),
				birthday: {
					$gt: firstConsentSwitchDate,
					$lte: secondConsentSwitchDate,
				},
			});
			query.push({
				...createRequiredConsents('parentConsents'),
				birthday: {
					$lt: firstConsentSwitchDate,
				},
			});
		}
		return query;
	}, []);

	return {
		$or: orConditions,
	};
};

/**
 * Creates a consent object, how it looked before it moved to users model
 * @param {*} user
 */
const userToConsent = (user) => ({
	_id: user._id,
	userId: user._id,
	requiresParentConsent: user.requiresParentConsent,
	consentStatus: user.consentStatus,
	...user.consent,
});

/**
 * data will be moved to the attribute consent
 * @param {Object} data
 */
const modifyDataForUserSchema = (data) => ({
	consent: {
		...data,
	},
});

module.exports = {
	createConsentFilterQuery,
	userToConsent,
	modifyDataForUserSchema,
};
{'fraction_non_alphanumeric': 0.15251572327044025, 'fraction_numerical': 0.0015723270440251573, 'mean_word_length': 3.390854184641933, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '2630610', 'n_tokens_mistral': 2068, 'n_tokens_neox': 1684, 'n_words': 311}