48 lines
1.4 KiB
JavaScript
48 lines
1.4 KiB
JavaScript
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' });
|
|
}
|
|
};
|