Fixed format of events

This commit is contained in:
Torsten Schulz
2024-06-23 17:32:45 +02:00
parent 692e989861
commit 8b89d8b800
26 changed files with 455 additions and 157 deletions

View File

@@ -21,7 +21,7 @@ const getAllEvents = async (req, res) => {
const filterEvents = async (req, res) => {
try {
const { id, 'event-places': eventPlaces, 'event-types': eventTypes, display } = req.query;
const request = req.body;
const where = {
[Op.or]: [
{
@@ -36,7 +36,7 @@ const filterEvents = async (req, res) => {
]
};
if (id === 'all') {
if (request.id === 'all') {
const events = await Event.findAll({
where,
include: [
@@ -49,7 +49,7 @@ const filterEvents = async (req, res) => {
return res.json({ events });
}
if (id === 'home') {
if (request.id === 'home') {
const events = await Event.findAll({
where: {
alsoOnHomepage: 1,
@@ -65,23 +65,23 @@ const filterEvents = async (req, res) => {
return res.json({ events });
}
if (!id && !eventPlaces && !eventTypes) {
return res.json({ events: [], eventPlaces: [], eventTypes: [], contactPersons: [] });
if (!request.id && !request.places && !request.types) {
return res.json({ events: [], places: [], types: [], contactPersons: [] });
}
if (id) {
where.id = id;
if (request.id) {
where.id = request.id;
}
if (eventPlaces) {
if (request.places && request.places.length > 0) {
where.event_place_id = {
[Op.in]: eventPlaces.split('|').map(id => parseInt(id))
[Op.in]: request.places.map(id => parseInt(id))
};
}
if (eventTypes) {
if (request.types && request.types.length > 0) {
where.eventTypeId = {
[Op.in]: eventTypes.split('|').map(id => parseInt(id))
[Op.in]: request.types.map(id => parseInt(id))
};
}
@@ -94,8 +94,7 @@ const filterEvents = async (req, res) => {
{ model: ContactPerson, as: 'contactPersons', through: { attributes: [] } }
]
});
const displayFields = display ? display.split('|') : [];
const displayFields = request.display ? request.display : [];
const filteredEvents = events.map(event => {
const filteredEvent = { ...event.toJSON() };