Initial commit: Club DynaSQY

This commit is contained in:
2026-08-23 09:04:47 +00:00
commit 0875890dc7
145 changed files with 16947 additions and 0 deletions
+32
View File
@@ -0,0 +1,32 @@
const pool = require('../config/db');
const { logActivity } = require('../services/activityLog');
exports.listUsers = async (req, res) => {
try {
const [rows] = await pool.query(
'SELECT id, prenom, nom, societe, email, telephone, role, actif, date_adhesion, date_echeance FROM users ORDER BY prenom ASC'
);
res.json(rows);
} catch (err) {
console.error(err);
res.status(500).json({ error: 'Server error' });
}
};
exports.updateUserRole = async (req, res) => {
try {
const { role } = req.body;
if (!['admin', 'member'].includes(role)) {
return res.status(400).json({ error: 'Role must be admin or member' });
}
const userId = req.params.id;
if (Number(userId) === req.user.id) {
return res.status(400).json({ error: 'Vous ne pouvez pas modifier votre propre rôle' });
}
await pool.query('UPDATE users SET role = ? WHERE id = ?', [role, userId]);
logActivity(req, 'role_changement', { targetUserId: userId, newRole: role });
} catch (err) {
console.error(err);
res.status(500).json({ error: 'Server error' });
}
};