<commit_before>const auth = require('@feathersjs/authentication');
const globalHooks = require('../../../hooks');

const restrictToCurrentSchool = globalHooks.ifNotLocal(globalHooks.restrictToCurrentSchool);

function createInfoText(user, data) {
	return `
	Ein neues Problem wurde gemeldet.\n
	User: ${user}\n
	Kategorie: ${data.category}\n
	Betreff: ${data.subject}\n
	Schaue für weitere Details und zur Bearbeitung bitte in den Helpdesk-Bereich der ${data.cloud}.\n\n
	Mit freundlichen Grüßen\n
	Deine ${data.cloud}`;
}

function createFeedbackText(user, data) {
	let text = `
	User: ${user}\n
	Schule: ${data.schoolName}\n
	Instanz: ${data.cloud}\n
	Bereich ausgewählt: ${data.category}\n
	`;

	if (data.desire && data.desire !== '') {
		text = `
		${text}
		User schrieb folgendes:\n
		Als ${data.role}\n
		möchte ich ${data.desire},\n
		um ${data.benefit}.\n
		Akzeptanzkriterien: ${data.acceptanceCriteria}
		`;
	} else {
		text = `
		${text}
		User meldet folgendes:\n
		Problem Kurzbeschreibung: ${data.subject}\n
		IST-Zustand: ${data.currentState}\n
		SOLL-Zustand: ${data.targetState}
		`;
		if (data.notes) {
			text = `
			${text}\n
			Anmerkungen: ${data.notes}
			`;
		}
	}
	return text;
}

const denyDbWriteOnType = (hook) => {
	if (hook.data.type === 'contactHPI') {
		hook.result = {}; // interrupts db interaction
	}
	return hook;
};

const feedback = () => {
	return (hook) => {
		const data = hook.data || {};
		if (data.type === 'contactAdmin') {
			globalHooks.sendEmail(hook, {
				subject: 'Ein Problem wurde gemeldet.',
				roles: ['helpdesk', 'administrator'],
				content: {
					text: createInfoText(
						(hook.params.account || {}).username || 'nouser', data,
					),
				},
			});
			// TODO: NOTIFICATION SERVICE
		} else {
			globalHooks.sendEmail(hook, {
				subject: data.subject || 'nosubject',
				emails: ['<EMAIL>'],
				content: {
					text: createFeedbackText(
						(hook.params.account || {}).username || 'nouser',
						data,
					),
				},<commit_msg>use title from forms as mail subject<commit_after>const auth = require('@feathersjs/authentication');
const globalHooks = require('../../../hooks');

const restrictToCurrentSchool = globalHooks.ifNotLocal(globalHooks.restrictToCurrentSchool);

function createInfoText(user, data) {
	return `
	Ein neues Problem wurde gemeldet.\n
	User: ${user}\n
	Kategorie: ${data.category}\n
	Betreff: ${data.subject}\n
	Schaue für weitere Details und zur Bearbeitung bitte in den Helpdesk-Bereich der ${data.cloud}.\n\n
	Mit freundlichen Grüßen\n
	Deine ${data.cloud}`;
}

function createFeedbackText(user, data) {
	let text = `
	User: ${user}\n
	Schule: ${data.schoolName}\n
	Instanz: ${data.cloud}\n
	Bereich ausgewählt: ${data.category}\n
	`;

	if (data.desire && data.desire !== '') {
		text = `
		${text}
		User schrieb folgendes:\n
		Als ${data.role}\n
		möchte ich ${data.desire},\n
		um ${data.benefit}.\n
		Akzeptanzkriterien: ${data.acceptanceCriteria}
		`;
	} else {
		text = `
		${text}
		User meldet folgendes:\n
		Problem Kurzbeschreibung: ${data.subject}\n
		IST-Zustand: ${data.currentState}\n
		SOLL-Zustand: ${data.targetState}
		`;
		if (data.notes) {
			text = `
			${text}\n
			Anmerkungen: ${data.notes}
			`;
		}
	}
	return text;
}

const denyDbWriteOnType = (hook) => {
	if (hook.data.type === 'contactHPI') {
		hook.result = {}; // interrupts db interaction
	}
	return hook;
};

const feedback = () => {
	return (hook) => {
		const data = hook.data || {};
		if (data.type === 'contactAdmin') {
			globalHooks.sendEmail(hook, {
				subject: 'Ein Problem wurde gemeldet.',
				roles: ['helpdesk', 'administrator'],
				content: {
					text: createInfoText(
						(hook.params.account || {}).username || 'nouser', data,
					),
				},
			});
			// TODO: NOTIFICATION SERVICE
		} else {
			globalHooks.sendEmail(hook, {
				subject: data.title || data.subject || 'nosubject',
				emails: ['<EMAIL>'],
				content: {
					text: createFeedbackText(
						(hook.params.account || {}).username || 'nouser',
						data,
					),
				},
{'fraction_non_alphanumeric': 0.17026022304832714, 'fraction_numerical': 0.0, 'mean_word_length': 3.406113537117904, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, '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': '1671395', 'n_tokens_mistral': 1663, 'n_tokens_neox': 1476, 'n_words': 305}