Added order

This commit is contained in:
Torsten Schulz
2024-07-10 17:48:40 +02:00
parent 7ab3be1465
commit d4811660fe
9 changed files with 15 additions and 12 deletions

View File

@@ -10,7 +10,8 @@ const getAllContactPersons = async (req, res) => {
as: 'positions', as: 'positions',
through: { attributes: [] } through: { attributes: [] }
} }
] ],
order: ['name']
}); });
res.json(contactPersons); res.json(contactPersons);
} catch (error) { } catch (error) {
@@ -74,13 +75,10 @@ const deleteContactPerson = async (req, res) => {
const filterContactPersons = async (req, res) => { const filterContactPersons = async (req, res) => {
try { try {
const { config: configString } = req.body; const { config: configString } = req.body;
console.log(configString, typeof configString);
const config = JSON.parse(configString); const config = JSON.parse(configString);
const where = {}; const where = {};
const having = []; const having = [];
console.log(config, typeof config);
console.log(config.selection);
if (config.selection.id && config.selection.id === 'all') { if (config.selection.id && config.selection.id === 'all') {
// No additional filter needed for "all" // No additional filter needed for "all"
} else if (config.selection.id) { } else if (config.selection.id) {
@@ -116,6 +114,7 @@ const filterContactPersons = async (req, res) => {
}, },
], ],
having: having.length > 0 ? { [Op.and]: having } : undefined, having: having.length > 0 ? { [Op.and]: having } : undefined,
order: ['name']
}); });
res.json(contactPersons); res.json(contactPersons);

View File

@@ -10,7 +10,8 @@ const getAllEvents = async (req, res) => {
{ model: EventPlace, as: 'eventPlace' }, { model: EventPlace, as: 'eventPlace' },
{ model: EventType, as: 'eventType' }, { model: EventType, as: 'eventType' },
{ model: ContactPerson, as: 'contactPersons', through: { attributes: [] } } { model: ContactPerson, as: 'contactPersons', through: { attributes: [] } }
] ],
order: ['name', 'date', 'time']
}); });
res.json(events); res.json(events);
} catch (error) { } catch (error) {
@@ -62,6 +63,7 @@ const filterEvents = async (req, res) => {
{ model: EventType, as: 'eventType' }, { model: EventType, as: 'eventType' },
{ model: ContactPerson, as: 'contactPersons', through: { attributes: [] } } { model: ContactPerson, as: 'contactPersons', through: { attributes: [] } }
], ],
order: ['name', 'date', 'time']
}); });
return res.json({ events }); return res.json({ events });
} }

View File

@@ -2,7 +2,9 @@ const { EventPlace } = require('../models');
const getAllEventPlaces = async (req, res) => { const getAllEventPlaces = async (req, res) => {
try { try {
const eventPlaces = await EventPlace.findAll(); const eventPlaces = await EventPlace.findAll({
order: [['name', 'ASC']]
});
res.json(eventPlaces); res.json(eventPlaces);
} catch (error) { } catch (error) {
res.status(500).json({ error: 'Failed to fetch event places' }); res.status(500).json({ error: 'Failed to fetch event places' });

View File

@@ -2,7 +2,7 @@ const { EventType } = require('../models');
const getAllEventTypes = async (req, res) => { const getAllEventTypes = async (req, res) => {
try { try {
const eventTypes = await EventType.findAll(); const eventTypes = await EventType.findAll({ order: [['caption', 'ASC']]});
res.json(eventTypes); res.json(eventTypes);
} catch (error) { } catch (error) {
res.status(500).json({ error: 'Failed to fetch event types' }); res.status(500).json({ error: 'Failed to fetch event types' });

View File

@@ -37,7 +37,7 @@ exports.saveImageDetails = async (req, res) => {
exports.getImages = async (req, res) => { exports.getImages = async (req, res) => {
try { try {
const images = await Image.findAll(); const images = await Image.findAll({ order: [['title', 'ASC']]});
res.status(200).json(images); res.status(200).json(images);
} catch (error) { } catch (error) {
console.error('Fehler beim Abrufen der Bilder:', error); console.error('Fehler beim Abrufen der Bilder:', error);

View File

@@ -9,7 +9,8 @@ const getAllInstitutions = async (req, res) => {
as: 'contactPersons', as: 'contactPersons',
through: { attributes: [] } through: { attributes: [] }
} }
] ],
order: [['name', 'ASC']]
}); });
res.json(institutions); res.json(institutions);
} catch (error) { } catch (error) {

View File

@@ -2,7 +2,7 @@ const { Position } = require('../models');
const getAllPositions = async (req, res) => { const getAllPositions = async (req, res) => {
try { try {
const positions = await Position.findAll(); const positions = await Position.findAll({order: [['caption', 'ASC']]});
res.json(positions); res.json(positions);
} catch (error) { } catch (error) {
res.status(500).json({ error: 'Failed to fetch positions' }); res.status(500).json({ error: 'Failed to fetch positions' });

View File

@@ -2,7 +2,7 @@ const { User } = require('../models');
exports.getAllUsers = async (req, res) => { exports.getAllUsers = async (req, res) => {
try { try {
const users = await User.findAll(); const users = await User.findAll({order: [['name', 'ASC']]});
res.status(200).json(users); res.status(200).json(users);
} catch (error) { } catch (error) {
res.status(500).json({ message: 'Error fetching users' }); res.status(500).json({ message: 'Error fetching users' });

View File

@@ -63,7 +63,6 @@ exports.getFilteredWorships = async (req, res) => {
[Op.gte]: new Date(), // Only include events from today onwards [Op.gte]: new Date(), // Only include events from today onwards
}; };
console.log(where, order);
try { try {
const worships = await Worship.findAll({ const worships = await Worship.findAll({
where, where,