Added Worship page rendering

This commit is contained in:
Torsten Schulz
2024-06-17 13:36:15 +02:00
parent 4f1390b794
commit 48a54ecdbb
17 changed files with 637 additions and 563 deletions

View File

@@ -1,4 +1,5 @@
const { Worship } = require('../models');
const { Worship, EventPlace } = require('../models');
const { Op } = require('sequelize'); // Importieren Sie die Operatoren von Sequelize
exports.getAllWorships = async (req, res) => {
try {
@@ -14,6 +15,7 @@ exports.createWorship = async (req, res) => {
const worship = await Worship.create(req.body);
res.status(201).json(worship);
} catch (error) {
console.log(error);
res.status(500).json({ message: 'Fehler beim Erstellen des Gottesdienstes' });
}
};
@@ -45,3 +47,31 @@ exports.deleteWorship = async (req, res) => {
res.status(500).json({ message: 'Fehler beim Löschen des Gottesdienstes' });
}
};
exports.getFilteredWorships = async (req, res) => {
const { location, orderBy } = req.query;
const where = {};
if (location && location !== '-1') {
where.eventPlaceId = location;
}
where.date = {
[Op.gte]: new Date(), // Only include events from today onwards
};
try {
const worships = await Worship.findAll({
where,
include: {
model: EventPlace,
as: 'eventPlace',
},
order: [orderBy.split(' ')],
});
res.status(200).json(worships);
} catch (error) {
console.log(error);
res.status(500).json({ message: 'Fehler beim Abrufen der gefilterten Gottesdienste' });
}
};