Add worship leaders functionality: Introduce worship leaders management by adding routes, controllers, and CSV import capabilities. Update worship management UI to support .csv file uploads for worship services, enhancing data handling and user experience.
All checks were successful
Deploy miriamgemeinde / deploy (push) Successful in 7s

This commit is contained in:
Torsten Schulz (local)
2026-04-29 18:04:05 +02:00
parent a2b1ebdb97
commit 7f01c004c8
11 changed files with 635 additions and 8 deletions

View File

@@ -0,0 +1,88 @@
const { WorshipLeader } = require('../models');
const { Op } = require('sequelize');
function normalizeLeaderPayload(body) {
const code = String(body.code || '').trim();
const name = String(body.name || '').trim();
const aliases = String(body.aliases || '').trim();
const active = body.active === undefined ? true : !!body.active;
return { code, name, aliases, active };
}
exports.getAllWorshipLeaders = async (req, res) => {
try {
const includeInactive = String(req.query?.includeInactive || '').toLowerCase();
const wantsInactive = includeInactive === '1' || includeInactive === 'true' || includeInactive === 'yes';
const where = wantsInactive ? undefined : { active: true };
const leaders = await WorshipLeader.findAll({
where,
order: [['code', 'ASC']],
});
res.json(leaders);
} catch (error) {
console.error('getAllWorshipLeaders:', error);
res.status(500).json({ error: 'Failed to fetch worship leaders' });
}
};
exports.createWorshipLeader = async (req, res) => {
try {
const payload = normalizeLeaderPayload(req.body || {});
if (!payload.code || !payload.name) {
return res.status(400).json({ message: 'code und name sind Pflichtfelder.' });
}
const existing = await WorshipLeader.findOne({ where: { code: payload.code } });
if (existing) {
return res.status(409).json({ message: `Kürzel "${payload.code}" existiert bereits.` });
}
const created = await WorshipLeader.create(payload);
res.status(201).json(created);
} catch (error) {
console.error('createWorshipLeader:', error);
res.status(500).json({ error: 'Failed to create worship leader' });
}
};
exports.updateWorshipLeader = async (req, res) => {
try {
const { id } = req.params;
const leader = await WorshipLeader.findByPk(id);
if (!leader) {
return res.status(404).json({ message: 'Worship leader not found' });
}
const payload = normalizeLeaderPayload(req.body || {});
if (!payload.code || !payload.name) {
return res.status(400).json({ message: 'code und name sind Pflichtfelder.' });
}
const codeClash = await WorshipLeader.findOne({
where: { code: payload.code, id: { [Op.ne]: id } },
});
if (codeClash) {
return res.status(409).json({ message: `Kürzel "${payload.code}" existiert bereits.` });
}
await leader.update(payload);
res.json(leader);
} catch (error) {
console.error('updateWorshipLeader:', error);
res.status(500).json({ error: 'Failed to update worship leader' });
}
};
exports.deleteWorshipLeader = async (req, res) => {
try {
const { id } = req.params;
const deleted = await WorshipLeader.destroy({ where: { id } });
if (!deleted) {
return res.status(404).json({ message: 'Worship leader not found' });
}
res.status(204).json();
} catch (error) {
console.error('deleteWorshipLeader:', error);
res.status(500).json({ error: 'Failed to delete worship leader' });
}
};