Added Worship page rendering
This commit is contained in:
@@ -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' });
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user