inital commit
This commit is contained in:
55
controllers/authController.js
Normal file
55
controllers/authController.js
Normal file
@@ -0,0 +1,55 @@
|
||||
const bcrypt = require('bcryptjs');
|
||||
const { User } = require('../models');
|
||||
const jwt = require('jsonwebtoken');
|
||||
|
||||
exports.register = async (req, res) => {
|
||||
const { name, email, password } = req.body;
|
||||
|
||||
if (!name || !email || !password) {
|
||||
return res.status(400).json({ message: 'Alle Felder sind erforderlich' });
|
||||
}
|
||||
|
||||
try {
|
||||
const hashedPassword = await bcrypt.hash(password, 10);
|
||||
const user = await User.create({ name, email, password: hashedPassword, active: true });
|
||||
|
||||
res.status(201).json({ message: 'Benutzer erfolgreich registriert', user });
|
||||
} catch (error) {
|
||||
if (error.name === 'SequelizeUniqueConstraintError') {
|
||||
return res.status(400).json({ message: 'Email-Adresse bereits in Verwendung' });
|
||||
}
|
||||
res.status(500).json({ message: 'Ein Fehler ist aufgetreten' });
|
||||
}
|
||||
};
|
||||
|
||||
exports.login = async (req, res) => {
|
||||
const { email, password } = req.body;
|
||||
if (!email || !password) {
|
||||
return res.status(400).json({ message: 'Email und Passwort sind erforderlich' });
|
||||
}
|
||||
|
||||
try {
|
||||
const user = await User.findOne({ where: { email } });
|
||||
|
||||
if (!user) {
|
||||
return res.status(401).json({ message: 'Ungültige Anmeldedaten' });
|
||||
}
|
||||
|
||||
const validPassword = await bcrypt.compare(password, user.password);
|
||||
|
||||
if (!validPassword) {
|
||||
return res.status(401).json({ message: 'Ungültige Anmeldedaten' });
|
||||
}
|
||||
|
||||
if (!user.active) {
|
||||
return res.status(403).json({ message: 'Benutzerkonto ist nicht aktiv' });
|
||||
}
|
||||
|
||||
const token = jwt.sign({ id: user.id, name: user.name, email: user.email }, 'zTxVgptmPl9!_dr%xxx9999(dd)', { expiresIn: '1h' });
|
||||
|
||||
res.status(200).json({ message: 'Login erfolgreich', token, 'user': user });
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
res.status(500).json({ message: 'Ein Fehler ist aufgetreten' });
|
||||
}
|
||||
};
|
||||
78
controllers/contactPersonController.js
Normal file
78
controllers/contactPersonController.js
Normal file
@@ -0,0 +1,78 @@
|
||||
const { ContactPerson, Position } = require('../models');
|
||||
|
||||
const getAllContactPersons = async (req, res) => {
|
||||
try {
|
||||
const contactPersons = await ContactPerson.findAll({
|
||||
include: [
|
||||
{
|
||||
model: Position,
|
||||
as: 'positions',
|
||||
through: { attributes: [] }
|
||||
}
|
||||
]
|
||||
});
|
||||
res.json(contactPersons);
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: 'Failed to fetch contact persons' });
|
||||
console.error(error);
|
||||
}
|
||||
};
|
||||
|
||||
const createContactPerson = async (req, res) => {
|
||||
try {
|
||||
const { positions, ...contactPersonData } = req.body;
|
||||
const contactPerson = await ContactPerson.create(contactPersonData);
|
||||
if (positions && positions.length > 0) {
|
||||
const positionIds = positions.map(position => position.id);
|
||||
await contactPerson.setPositions(positionIds);
|
||||
}
|
||||
res.status(201).json(contactPerson);
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: 'Failed to create contact person' });
|
||||
console.error(error);
|
||||
}
|
||||
};
|
||||
|
||||
const updateContactPerson = async (req, res) => {
|
||||
try {
|
||||
const { id } = req.params;
|
||||
const { positions, ...contactPersonData } = req.body;
|
||||
const contactPerson = await ContactPerson.findByPk(id);
|
||||
if (!contactPerson) {
|
||||
return res.status(404).json({ error: 'Contact person not found' });
|
||||
}
|
||||
await contactPerson.update(contactPersonData);
|
||||
if (positions && positions.length > 0) {
|
||||
const positionIds = positions.map(position => position.id);
|
||||
await contactPerson.setPositions(positionIds);
|
||||
}
|
||||
res.status(200).json(contactPerson);
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: 'Failed to update contact person' });
|
||||
console.error(error);
|
||||
}
|
||||
};
|
||||
|
||||
const deleteContactPerson = async (req, res) => {
|
||||
try {
|
||||
const { id } = req.params;
|
||||
const deleted = await ContactPerson.destroy({
|
||||
where: { id: id }
|
||||
});
|
||||
if (deleted) {
|
||||
res.status(204).json();
|
||||
} else {
|
||||
res.status(404).json({ error: 'Contact person not found' });
|
||||
}
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: 'Failed to delete contact person' });
|
||||
console.error(error);
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
getAllContactPersons,
|
||||
createContactPerson,
|
||||
updateContactPerson,
|
||||
deleteContactPerson
|
||||
};
|
||||
74
controllers/eventController.js
Normal file
74
controllers/eventController.js
Normal file
@@ -0,0 +1,74 @@
|
||||
const { Event, Institution, EventPlace, ContactPerson } = require('../models');
|
||||
|
||||
const getAllEvents = async (req, res) => {
|
||||
try {
|
||||
const events = await Event.findAll({
|
||||
include: [
|
||||
{ model: Institution, as: 'institution' },
|
||||
{ model: EventPlace, as: 'eventPlace' },
|
||||
{ model: ContactPerson, as: 'contactPersons', through: { attributes: [] } }
|
||||
]
|
||||
});
|
||||
res.json(events);
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: 'Failed to fetch events' });
|
||||
console.error(error);
|
||||
}
|
||||
};
|
||||
|
||||
const createEvent = async (req, res) => {
|
||||
try {
|
||||
const { contactPersonIds, ...eventData } = req.body;
|
||||
const event = await Event.create(eventData);
|
||||
if (contactPersonIds) {
|
||||
await event.setContactPersons(contactPersonIds);
|
||||
}
|
||||
res.status(201).json(event);
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: 'Failed to create event' });
|
||||
console.error(error);
|
||||
}
|
||||
};
|
||||
|
||||
const updateEvent = async (req, res) => {
|
||||
try {
|
||||
const { id } = req.params;
|
||||
const { contactPersonIds, ...eventData } = req.body;
|
||||
const event = await Event.findByPk(id);
|
||||
if (!event) {
|
||||
return res.status(404).json({ error: 'Event not found' });
|
||||
}
|
||||
await event.update(eventData);
|
||||
if (contactPersonIds) {
|
||||
await event.setContactPersons(contactPersonIds);
|
||||
}
|
||||
res.status(200).json(event);
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: 'Failed to update event' });
|
||||
console.error(error);
|
||||
}
|
||||
};
|
||||
|
||||
const deleteEvent = async (req, res) => {
|
||||
try {
|
||||
const { id } = req.params;
|
||||
const deleted = await Event.destroy({
|
||||
where: { id: id }
|
||||
});
|
||||
if (deleted) {
|
||||
res.status(204).json();
|
||||
} else {
|
||||
res.status(404).json({ error: 'Event not found' });
|
||||
}
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: 'Failed to delete event' });
|
||||
console.error(error);
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
getAllEvents,
|
||||
createEvent,
|
||||
updateEvent,
|
||||
deleteEvent
|
||||
};
|
||||
61
controllers/eventPlaceController.js
Normal file
61
controllers/eventPlaceController.js
Normal file
@@ -0,0 +1,61 @@
|
||||
const { EventPlace } = require('../models');
|
||||
|
||||
const getAllEventPlaces = async (req, res) => {
|
||||
try {
|
||||
const eventPlaces = await EventPlace.findAll();
|
||||
res.json(eventPlaces);
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: 'Failed to fetch event places' });
|
||||
}
|
||||
};
|
||||
|
||||
const createEventPlace = async (req, res) => {
|
||||
try {
|
||||
const eventPlace = await EventPlace.create(req.body);
|
||||
res.status(201).json(eventPlace);
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: 'Failed to create event place' });
|
||||
console.log(req.body);
|
||||
console.log(error);
|
||||
}
|
||||
};
|
||||
|
||||
const updateEventPlace = async (req, res) => {
|
||||
try {
|
||||
const { id } = req.params;
|
||||
const [updated] = await EventPlace.update(req.body, {
|
||||
where: { id: id }
|
||||
});
|
||||
if (updated) {
|
||||
const updatedEventPlace = await EventPlace.findOne({ where: { id: id } });
|
||||
res.status(200).json(updatedEventPlace);
|
||||
} else {
|
||||
res.status(404).json({ error: 'Event place not found' });
|
||||
}
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: 'Failed to update event place' });
|
||||
}
|
||||
};
|
||||
|
||||
const deleteEventPlace = async (req, res) => {
|
||||
try {
|
||||
const { id } = req.params;
|
||||
const deleted = await EventPlace.destroy({
|
||||
where: { id: id }
|
||||
});
|
||||
if (deleted) {
|
||||
res.status(204).json();
|
||||
} else {
|
||||
res.status(404).json({ error: 'Event place not found' });
|
||||
}
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: 'Failed to delete event place' });
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
getAllEventPlaces,
|
||||
createEventPlace,
|
||||
updateEventPlace,
|
||||
deleteEventPlace
|
||||
};
|
||||
59
controllers/eventtypecontroller.js
Normal file
59
controllers/eventtypecontroller.js
Normal file
@@ -0,0 +1,59 @@
|
||||
const { EventType } = require('../models');
|
||||
|
||||
const getAllEventTypes = async (req, res) => {
|
||||
try {
|
||||
const eventTypes = await EventType.findAll();
|
||||
res.json(eventTypes);
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: 'Failed to fetch event types' });
|
||||
}
|
||||
};
|
||||
|
||||
const createEventType = async (req, res) => {
|
||||
try {
|
||||
const eventType = await EventType.create(req.body);
|
||||
res.status(201).json(eventType);
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: 'Failed to create event type' });
|
||||
}
|
||||
};
|
||||
|
||||
const updateEventType = async (req, res) => {
|
||||
try {
|
||||
const { id } = req.params;
|
||||
const [updated] = await EventType.update(req.body, {
|
||||
where: { id: id }
|
||||
});
|
||||
if (updated) {
|
||||
const updatedEventType = await EventType.findOne({ where: { id: id } });
|
||||
res.status(200).json(updatedEventType);
|
||||
} else {
|
||||
res.status(404).json({ error: 'Event type not found' });
|
||||
}
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: 'Failed to update event type' });
|
||||
}
|
||||
};
|
||||
|
||||
const deleteEventType = async (req, res) => {
|
||||
try {
|
||||
const { id } = req.params;
|
||||
const deleted = await EventType.destroy({
|
||||
where: { id: id }
|
||||
});
|
||||
if (deleted) {
|
||||
res.status(204).json();
|
||||
} else {
|
||||
res.status(404).json({ error: 'Event type not found' });
|
||||
}
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: 'Failed to delete event type' });
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
getAllEventTypes,
|
||||
createEventType,
|
||||
updateEventType,
|
||||
deleteEventType
|
||||
};
|
||||
76
controllers/institutionController.js
Normal file
76
controllers/institutionController.js
Normal file
@@ -0,0 +1,76 @@
|
||||
const { Institution, ContactPerson } = require('../models');
|
||||
|
||||
const getAllInstitutions = async (req, res) => {
|
||||
try {
|
||||
const institutions = await Institution.findAll({
|
||||
include: [
|
||||
{
|
||||
model: ContactPerson,
|
||||
as: 'contactPersons',
|
||||
through: { attributes: [] }
|
||||
}
|
||||
]
|
||||
});
|
||||
res.json(institutions);
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: 'Failed to fetch institutions' });
|
||||
console.error(error);
|
||||
}
|
||||
};
|
||||
|
||||
const createInstitution = async (req, res) => {
|
||||
try {
|
||||
const { contactPersonIds, ...institutionData } = req.body;
|
||||
const institution = await Institution.create(institutionData);
|
||||
if (contactPersonIds) {
|
||||
await institution.setContactPersons(contactPersonIds);
|
||||
}
|
||||
res.status(201).json(institution);
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: 'Failed to create institution' });
|
||||
console.error(error);
|
||||
}
|
||||
};
|
||||
|
||||
const updateInstitution = async (req, res) => {
|
||||
try {
|
||||
const { id } = req.params;
|
||||
const { contactPersonIds, ...institutionData } = req.body;
|
||||
const institution = await Institution.findByPk(id);
|
||||
if (!institution) {
|
||||
return res.status(404).json({ error: 'Institution not found' });
|
||||
}
|
||||
await institution.update(institutionData);
|
||||
if (contactPersonIds) {
|
||||
await institution.setContactPersons(contactPersonIds);
|
||||
}
|
||||
res.status(200).json(institution);
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: 'Failed to update institution' });
|
||||
console.error(error);
|
||||
}
|
||||
};
|
||||
|
||||
const deleteInstitution = async (req, res) => {
|
||||
try {
|
||||
const { id } = req.params;
|
||||
const deleted = await Institution.destroy({
|
||||
where: { id: id }
|
||||
});
|
||||
if (deleted) {
|
||||
res.status(204).json();
|
||||
} else {
|
||||
res.status(404).json({ error: 'Institution not found' });
|
||||
}
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: 'Failed to delete institution' });
|
||||
console.error(error);
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
getAllInstitutions,
|
||||
createInstitution,
|
||||
updateInstitution,
|
||||
deleteInstitution
|
||||
};
|
||||
23
controllers/menuDataController.js
Normal file
23
controllers/menuDataController.js
Normal file
@@ -0,0 +1,23 @@
|
||||
// controllers/menuDataController.js
|
||||
|
||||
const fetchMenuData = require('../utils/fetchMenuData');
|
||||
|
||||
exports.getMenuData = async (req, res) => {
|
||||
try {
|
||||
const menuData = await fetchMenuData();
|
||||
res.json(menuData);
|
||||
} catch (error) {
|
||||
res.status(500).send('Error fetching menu data');
|
||||
}
|
||||
};
|
||||
|
||||
exports.saveMenuData = async (req, res) => {
|
||||
try {
|
||||
const menuData = req.body;
|
||||
await MenuItem.destroy({ where: {} });
|
||||
await MenuItem.bulkCreate(menuData);
|
||||
res.status(200).send('Menü-Daten erfolgreich gespeichert');
|
||||
} catch (error) {
|
||||
res.status(500).send('Fehler beim Speichern der Menü-Daten');
|
||||
}
|
||||
};
|
||||
48
controllers/pageController.js
Normal file
48
controllers/pageController.js
Normal file
@@ -0,0 +1,48 @@
|
||||
// controllers/pageController.js
|
||||
const { Page } = require('../models');
|
||||
|
||||
exports.getMenuData = async (req, res) => {
|
||||
try {
|
||||
const pages = await Page.findAll({
|
||||
attributes: ['link', 'name']
|
||||
});
|
||||
res.json(pages);
|
||||
} catch (error) {
|
||||
console.error('Fehler beim Abrufen der Seiten:', error);
|
||||
res.status(500).json({ message: 'Fehler beim Abrufen der Seiten' });
|
||||
}
|
||||
};
|
||||
|
||||
exports.getPageContent = async (req, res) => {
|
||||
try {
|
||||
const page = await Page.findOne({
|
||||
where: { link: req.query.link }
|
||||
});
|
||||
if (page) {
|
||||
res.json({ content: page.content });
|
||||
} else {
|
||||
res.json({ content: "" });
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Fehler beim Laden des Seiteninhalts:', error);
|
||||
res.status(500).json({ message: 'Fehler beim Laden des Seiteninhalts' });
|
||||
}
|
||||
};
|
||||
|
||||
exports.savePageContent = async (req, res) => {
|
||||
try {
|
||||
const { link, name, content } = req.body;
|
||||
let page = await Page.findOne({ where: { link } });
|
||||
if (page) {
|
||||
page.content = content;
|
||||
page.name = name;
|
||||
} else {
|
||||
page = await Page.create({ link, name, content });
|
||||
}
|
||||
await page.save();
|
||||
res.json({ message: 'Seiteninhalt gespeichert', page });
|
||||
} catch (error) {
|
||||
console.error('Fehler beim Speichern des Seiteninhalts:', error);
|
||||
res.status(500).json({ message: 'Fehler beim Speichern des Seiteninhalts' });
|
||||
}
|
||||
};
|
||||
59
controllers/positionController.js
Normal file
59
controllers/positionController.js
Normal file
@@ -0,0 +1,59 @@
|
||||
const { Position } = require('../models');
|
||||
|
||||
const getAllPositions = async (req, res) => {
|
||||
try {
|
||||
const positions = await Position.findAll();
|
||||
res.json(positions);
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: 'Failed to fetch positions' });
|
||||
}
|
||||
};
|
||||
|
||||
const createPosition = async (req, res) => {
|
||||
try {
|
||||
const position = await Position.create(req.body);
|
||||
res.status(201).json(position);
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: 'Failed to create position' });
|
||||
}
|
||||
};
|
||||
|
||||
const updatePosition = async (req, res) => {
|
||||
try {
|
||||
const { id } = req.params;
|
||||
const [updated] = await Position.update(req.body, {
|
||||
where: { id: id }
|
||||
});
|
||||
if (updated) {
|
||||
const updatedPosition = await Position.findOne({ where: { id: id } });
|
||||
res.status(200).json(updatedPosition);
|
||||
} else {
|
||||
res.status(404).json({ error: 'Position not found' });
|
||||
}
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: 'Failed to update position' });
|
||||
}
|
||||
};
|
||||
|
||||
const deletePosition = async (req, res) => {
|
||||
try {
|
||||
const { id } = req.params;
|
||||
const deleted = await Position.destroy({
|
||||
where: { id: id }
|
||||
});
|
||||
if (deleted) {
|
||||
res.status(204).json();
|
||||
} else {
|
||||
res.status(404).json({ error: 'Position not found' });
|
||||
}
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: 'Failed to delete position' });
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
getAllPositions,
|
||||
createPosition,
|
||||
updatePosition,
|
||||
deletePosition
|
||||
};
|
||||
47
controllers/worshipController.js
Normal file
47
controllers/worshipController.js
Normal file
@@ -0,0 +1,47 @@
|
||||
const { Worship } = require('../models');
|
||||
|
||||
exports.getAllWorships = async (req, res) => {
|
||||
try {
|
||||
const worships = await Worship.findAll();
|
||||
res.status(200).json(worships);
|
||||
} catch (error) {
|
||||
res.status(500).json({ message: 'Fehler beim Abrufen der Gottesdienste' });
|
||||
}
|
||||
};
|
||||
|
||||
exports.createWorship = async (req, res) => {
|
||||
try {
|
||||
const worship = await Worship.create(req.body);
|
||||
res.status(201).json(worship);
|
||||
} catch (error) {
|
||||
res.status(500).json({ message: 'Fehler beim Erstellen des Gottesdienstes' });
|
||||
}
|
||||
};
|
||||
|
||||
exports.updateWorship = async (req, res) => {
|
||||
try {
|
||||
const worship = await Worship.findByPk(req.params.id);
|
||||
if (worship) {
|
||||
await worship.update(req.body);
|
||||
res.status(200).json(worship);
|
||||
} else {
|
||||
res.status(404).json({ message: 'Gottesdienst nicht gefunden' });
|
||||
}
|
||||
} catch (error) {
|
||||
res.status(500).json({ message: 'Fehler beim Aktualisieren des Gottesdienstes' });
|
||||
}
|
||||
};
|
||||
|
||||
exports.deleteWorship = async (req, res) => {
|
||||
try {
|
||||
const worship = await Worship.findByPk(req.params.id);
|
||||
if (worship) {
|
||||
await worship.destroy();
|
||||
res.status(200).json({ message: 'Gottesdienst erfolgreich gelöscht' });
|
||||
} else {
|
||||
res.status(404).json({ message: 'Gottesdienst nicht gefunden' });
|
||||
}
|
||||
} catch (error) {
|
||||
res.status(500).json({ message: 'Fehler beim Löschen des Gottesdienstes' });
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user