Fixed worship edit functionality

This commit is contained in:
Torsten Schulz
2024-09-06 12:35:54 +02:00
parent 78555bb66a
commit a869f2d16a
2 changed files with 15 additions and 4 deletions

View File

@@ -1,9 +1,18 @@
const { Worship, EventPlace, Sequelize } = require('../models'); const { Worship, EventPlace, Sequelize } = require('../models');
const { Op, fn } = require('sequelize'); // Importieren Sie die Operatoren von Sequelize const { Op, fn, literal } = require('sequelize'); // Importieren Sie die Operatoren von Sequelize
exports.getAllWorships = async (req, res) => { exports.getAllWorships = async (req, res) => {
try { try {
const worships = await Worship.findAll(); const worships = await Worship.findAll({
where: {
date: {
[Op.gt]: literal("DATE_SUB(NOW(), INTERVAL 4 WEEK)")
},
},
order: [
['date', 'DESC']
],
});
res.status(200).json(worships); res.status(200).json(worships);
} catch (error) { } catch (error) {
res.status(500).json({ message: 'Fehler beim Abrufen der Gottesdienste' }); res.status(500).json({ message: 'Fehler beim Abrufen der Gottesdienste' });
@@ -51,7 +60,9 @@ exports.deleteWorship = async (req, res) => {
exports.getFilteredWorships = async (req, res) => { exports.getFilteredWorships = async (req, res) => {
const { location, order } = req.query; const { location, order } = req.query;
const where = {}; const where = {};
if (order.trim() === '') {
order = 'date DESC';
}
const locations = JSON.parse(location); const locations = JSON.parse(location);
if (location && locations.length > 0) { if (location && locations.length > 0) {
where.eventPlaceId = { where.eventPlaceId = {

View File

@@ -94,7 +94,7 @@ export default {
async fetchWorships() { async fetchWorships() {
try { try {
const response = await axios.get('/worships'); const response = await axios.get('/worships');
this.worships = response.data.reverse(); this.worships = response.data;
} catch (error) { } catch (error) {
console.error('Fehler beim Abrufen der Gottesdienste:', error); console.error('Fehler beim Abrufen der Gottesdienste:', error);
} }