Some fixes, added Events in edit

This commit is contained in:
Torsten Schulz
2024-06-22 17:56:26 +02:00
parent 97c72540cf
commit 692e989861
11 changed files with 450 additions and 17 deletions

View File

@@ -1,4 +1,5 @@
const { ContactPerson, Position } = require('../models');
const { ContactPerson, Position, Event, EventType, EventPlace } = require('../models');
const { Op } = require('sequelize');
const getAllContactPersons = async (req, res) => {
try {
@@ -70,9 +71,61 @@ 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 = {};
console.log(config, typeof config);
console.log(config.selection);
if (config.selection.id && config.selection.id === 'all') {
} else if (config.selection.id) {
where.id = config.selection.id;
} else {
const filters = [];
if (config.selection.types && config.selection.types.length > 0) {
filters.push({ '$positions.id$': { [Op.in]: config.selection.types } });
}
if (config.selection.places && config.selection.places.length > 0) {
filters.push({ '$events.eventPlaceId$': { [Op.in]: config.selection.places } });
}
if (filters.length > 0) {
where[Op.and] = filters;
}
}
const contactPersons = await ContactPerson.findAll({
where,
include: [
{
model: Position,
as: 'positions',
through: { attributes: [] },
},
{
model: Event,
as: 'events',
through: { attributes: [] },
},
],
});
res.json(contactPersons);
} catch (error) {
res.status(500).json({ error: 'Failed to fetch contact persons' });
console.error(error);
}
};
module.exports = {
getAllContactPersons,
createContactPerson,
updateContactPerson,
deleteContactPerson
deleteContactPerson,
filterContactPersons
};

View File

@@ -123,6 +123,7 @@ const filterEvents = async (req, res) => {
const createEvent = async (req, res) => {
try {
const { contactPersonIds, ...eventData } = req.body;
eventData.alsoOnHomepage = eventData.alsoOnHomepage ?? 0;
const event = await Event.create(eventData);
if (contactPersonIds) {
await event.setContactPersons(contactPersonIds);