From a869f2d16a4fd8dbfbdecac1ffad9c0c71543034 Mon Sep 17 00:00:00 2001 From: Torsten Schulz Date: Fri, 6 Sep 2024 12:35:54 +0200 Subject: [PATCH] Fixed worship edit functionality --- controllers/worshipController.js | 17 ++++++++++++++--- src/content/admin/WorshipManagement.vue | 2 +- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/controllers/worshipController.js b/controllers/worshipController.js index b421702..0557c8f 100644 --- a/controllers/worshipController.js +++ b/controllers/worshipController.js @@ -1,9 +1,18 @@ 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) => { 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); } catch (error) { res.status(500).json({ message: 'Fehler beim Abrufen der Gottesdienste' }); @@ -51,7 +60,9 @@ exports.deleteWorship = async (req, res) => { exports.getFilteredWorships = async (req, res) => { const { location, order } = req.query; const where = {}; - + if (order.trim() === '') { + order = 'date DESC'; + } const locations = JSON.parse(location); if (location && locations.length > 0) { where.eventPlaceId = { diff --git a/src/content/admin/WorshipManagement.vue b/src/content/admin/WorshipManagement.vue index 9df5d5d..5d9bc2d 100644 --- a/src/content/admin/WorshipManagement.vue +++ b/src/content/admin/WorshipManagement.vue @@ -94,7 +94,7 @@ export default { async fetchWorships() { try { const response = await axios.get('/worships'); - this.worships = response.data.reverse(); + this.worships = response.data; } catch (error) { console.error('Fehler beim Abrufen der Gottesdienste:', error); }