IA Assistant version initiale
This commit is contained in:
1 parent
3e8508d48b
commit
662003fdd3
29 files changed
+4253
-10
No files matched your search
@@ -73,7 +73,7 @@ const router = Router();
|
||||
router.get('/users', (req, res) => {
|
||||
const users = db.prepare(`
|
||||
SELECT
|
||||
id, email, display_name, role, email_verified, totp_enabled, status, created_at,
|
||||
id, email, display_name, role, email_verified, totp_enabled, status, created_at, ai_enabled,
|
||||
(SELECT COUNT(*) FROM plateformes p WHERE p.user_id = users.id) AS nb_plateformes,
|
||||
(SELECT COUNT(*) FROM investissements i
|
||||
JOIN investisseurs inv ON inv.id = i.investisseur_id
|
||||
@@ -156,6 +156,23 @@ router.patch('/users/:id/status', (req, res, next) => {
|
||||
} catch (e) { next(e); }
|
||||
});
|
||||
|
||||
/** Active / désactive l'accès à l'Assistant IA pour un utilisateur (décision admin) */
|
||||
const PatchAiAccessSchema = z.object({
|
||||
aiEnabled: z.boolean(),
|
||||
});
|
||||
|
||||
router.patch('/users/:id/ai-access', (req, res, next) => {
|
||||
try {
|
||||
const { aiEnabled } = PatchAiAccessSchema.parse(req.body);
|
||||
const targetId = Number(req.params.id);
|
||||
const r = db.prepare("UPDATE users SET ai_enabled=?, updated_at=datetime('now') WHERE id=?")
|
||||
.run(aiEnabled ? 1 : 0, targetId);
|
||||
if (r.changes === 0) throw new HttpError(404, 'Utilisateur introuvable');
|
||||
audit(req, { action: 'ai_access_changed', category: 'ai', actorId: req.user.id, targetUserId: targetId, details: { ai_enabled: aiEnabled } });
|
||||
res.json({ id: targetId, aiEnabled });
|
||||
} catch (e) { next(e); }
|
||||
});
|
||||
|
||||
/** Modifie le rôle d'un utilisateur */
|
||||
const PatchRoleSchema = z.object({
|
||||
role: z.enum(['user', 'admin']),
|
||||
|
||||
Reference in new issue
Block a user