Some fixes, added Events in edit
This commit is contained in:
@@ -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
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user