From d4811660fe0e0dd9653f885173ee35540db26ce3 Mon Sep 17 00:00:00 2001 From: Torsten Schulz Date: Wed, 10 Jul 2024 17:48:40 +0200 Subject: [PATCH] Added order --- controllers/contactPersonController.js | 7 +++---- controllers/eventController.js | 4 +++- controllers/eventPlaceController.js | 4 +++- controllers/eventtypecontroller.js | 2 +- controllers/imageController.js | 2 +- controllers/institutionController.js | 3 ++- controllers/positionController.js | 2 +- controllers/userController.js | 2 +- controllers/worshipController.js | 1 - 9 files changed, 15 insertions(+), 12 deletions(-) diff --git a/controllers/contactPersonController.js b/controllers/contactPersonController.js index 7d86ae9..67e2831 100644 --- a/controllers/contactPersonController.js +++ b/controllers/contactPersonController.js @@ -10,7 +10,8 @@ const getAllContactPersons = async (req, res) => { as: 'positions', through: { attributes: [] } } - ] + ], + order: ['name'] }); res.json(contactPersons); } catch (error) { @@ -74,13 +75,10 @@ const deleteContactPerson = async (req, res) => { const filterContactPersons = async (req, res) => { try { const { config: configString } = req.body; - console.log(configString, typeof configString); const config = JSON.parse(configString); const where = {}; const having = []; - console.log(config, typeof config); - console.log(config.selection); if (config.selection.id && config.selection.id === 'all') { // No additional filter needed for "all" } else if (config.selection.id) { @@ -116,6 +114,7 @@ const filterContactPersons = async (req, res) => { }, ], having: having.length > 0 ? { [Op.and]: having } : undefined, + order: ['name'] }); res.json(contactPersons); diff --git a/controllers/eventController.js b/controllers/eventController.js index 94c9c96..ae285c1 100644 --- a/controllers/eventController.js +++ b/controllers/eventController.js @@ -10,7 +10,8 @@ const getAllEvents = async (req, res) => { { model: EventPlace, as: 'eventPlace' }, { model: EventType, as: 'eventType' }, { model: ContactPerson, as: 'contactPersons', through: { attributes: [] } } - ] + ], + order: ['name', 'date', 'time'] }); res.json(events); } catch (error) { @@ -62,6 +63,7 @@ const filterEvents = async (req, res) => { { model: EventType, as: 'eventType' }, { model: ContactPerson, as: 'contactPersons', through: { attributes: [] } } ], + order: ['name', 'date', 'time'] }); return res.json({ events }); } diff --git a/controllers/eventPlaceController.js b/controllers/eventPlaceController.js index 7ebc1d0..8526cf9 100644 --- a/controllers/eventPlaceController.js +++ b/controllers/eventPlaceController.js @@ -2,7 +2,9 @@ const { EventPlace } = require('../models'); const getAllEventPlaces = async (req, res) => { try { - const eventPlaces = await EventPlace.findAll(); + const eventPlaces = await EventPlace.findAll({ + order: [['name', 'ASC']] + }); res.json(eventPlaces); } catch (error) { res.status(500).json({ error: 'Failed to fetch event places' }); diff --git a/controllers/eventtypecontroller.js b/controllers/eventtypecontroller.js index a0ed881..edcc9ce 100644 --- a/controllers/eventtypecontroller.js +++ b/controllers/eventtypecontroller.js @@ -2,7 +2,7 @@ const { EventType } = require('../models'); const getAllEventTypes = async (req, res) => { try { - const eventTypes = await EventType.findAll(); + const eventTypes = await EventType.findAll({ order: [['caption', 'ASC']]}); res.json(eventTypes); } catch (error) { res.status(500).json({ error: 'Failed to fetch event types' }); diff --git a/controllers/imageController.js b/controllers/imageController.js index 7780e34..0353c26 100644 --- a/controllers/imageController.js +++ b/controllers/imageController.js @@ -37,7 +37,7 @@ exports.saveImageDetails = async (req, res) => { exports.getImages = async (req, res) => { try { - const images = await Image.findAll(); + const images = await Image.findAll({ order: [['title', 'ASC']]}); res.status(200).json(images); } catch (error) { console.error('Fehler beim Abrufen der Bilder:', error); diff --git a/controllers/institutionController.js b/controllers/institutionController.js index 577c407..196e938 100644 --- a/controllers/institutionController.js +++ b/controllers/institutionController.js @@ -9,7 +9,8 @@ const getAllInstitutions = async (req, res) => { as: 'contactPersons', through: { attributes: [] } } - ] + ], + order: [['name', 'ASC']] }); res.json(institutions); } catch (error) { diff --git a/controllers/positionController.js b/controllers/positionController.js index 7e8bf33..f656888 100644 --- a/controllers/positionController.js +++ b/controllers/positionController.js @@ -2,7 +2,7 @@ const { Position } = require('../models'); const getAllPositions = async (req, res) => { try { - const positions = await Position.findAll(); + const positions = await Position.findAll({order: [['caption', 'ASC']]}); res.json(positions); } catch (error) { res.status(500).json({ error: 'Failed to fetch positions' }); diff --git a/controllers/userController.js b/controllers/userController.js index 8ce9dea..8417681 100644 --- a/controllers/userController.js +++ b/controllers/userController.js @@ -2,7 +2,7 @@ const { User } = require('../models'); exports.getAllUsers = async (req, res) => { try { - const users = await User.findAll(); + const users = await User.findAll({order: [['name', 'ASC']]}); res.status(200).json(users); } catch (error) { res.status(500).json({ message: 'Error fetching users' }); diff --git a/controllers/worshipController.js b/controllers/worshipController.js index 5c57158..b2b0e7d 100644 --- a/controllers/worshipController.js +++ b/controllers/worshipController.js @@ -63,7 +63,6 @@ exports.getFilteredWorships = async (req, res) => { [Op.gte]: new Date(), // Only include events from today onwards }; - console.log(where, order); try { const worships = await Worship.findAll({ where,