xpeditis2.0/apps/backend/diagnostic-complet.sh
2025-12-05 13:55:40 +01:00

193 lines
6.9 KiB
Bash
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# Script de diagnostic complet pour l'envoi d'email aux transporteurs
# Ce script fait TOUT automatiquement
set -e # Arrêter en cas d'erreur
# Couleurs
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
echo ""
echo "╔════════════════════════════════════════════════════════════╗"
echo "║ 🔍 DIAGNOSTIC COMPLET - Email Transporteur ║"
echo "╚════════════════════════════════════════════════════════════╝"
echo ""
# Fonction pour afficher les étapes
step_header() {
echo ""
echo -e "${BLUE}╔════════════════════════════════════════════════════════════╗${NC}"
echo -e "${BLUE}$1${NC}"
echo -e "${BLUE}╚════════════════════════════════════════════════════════════╝${NC}"
echo ""
}
# Fonction pour les succès
success() {
echo -e "${GREEN}$1${NC}"
}
# Fonction pour les erreurs
error() {
echo -e "${RED}$1${NC}"
}
# Fonction pour les warnings
warning() {
echo -e "${YELLOW}⚠️ $1${NC}"
}
# Fonction pour les infos
info() {
echo -e "${BLUE} $1${NC}"
}
# Aller dans le répertoire backend
cd "$(dirname "$0")"
# ============================================================
# ÉTAPE 1: Arrêter le backend
# ============================================================
step_header "ÉTAPE 1/5: Arrêt du backend actuel"
BACKEND_PIDS=$(lsof -ti:4000 2>/dev/null || true)
if [ -n "$BACKEND_PIDS" ]; then
info "Processus backend trouvés: $BACKEND_PIDS"
kill -9 $BACKEND_PIDS 2>/dev/null || true
sleep 2
success "Backend arrêté"
else
info "Aucun backend en cours d'exécution"
fi
# ============================================================
# ÉTAPE 2: Vérifier les modifications
# ============================================================
step_header "ÉTAPE 2/5: Vérification des modifications"
if grep -q "Using direct IP" src/infrastructure/email/email.adapter.ts; then
success "Modifications DNS présentes dans email.adapter.ts"
else
error "Modifications DNS ABSENTES dans email.adapter.ts"
error "Le fix n'a pas été appliqué correctement!"
exit 1
fi
# ============================================================
# ÉTAPE 3: Test de connexion SMTP (sans backend)
# ============================================================
step_header "ÉTAPE 3/5: Test de connexion SMTP directe"
info "Exécution de debug-email-flow.js..."
echo ""
if node debug-email-flow.js > /tmp/email-test.log 2>&1; then
success "Test SMTP réussi!"
echo ""
echo "Résultats du test:"
echo "─────────────────"
tail -15 /tmp/email-test.log
else
error "Test SMTP échoué!"
echo ""
echo "Logs d'erreur:"
echo "──────────────"
cat /tmp/email-test.log
echo ""
error "ARRÊT: La connexion SMTP ne fonctionne pas"
error "Vérifiez vos credentials SMTP dans .env"
exit 1
fi
# ============================================================
# ÉTAPE 4: Redémarrer le backend
# ============================================================
step_header "ÉTAPE 4/5: Redémarrage du backend"
info "Démarrage du backend en arrière-plan..."
# Démarrer le backend
npm run dev > /tmp/backend.log 2>&1 &
BACKEND_PID=$!
info "Backend démarré (PID: $BACKEND_PID)"
info "Attente de l'initialisation (15 secondes)..."
# Attendre que le backend démarre
sleep 15
# Vérifier que le backend tourne
if kill -0 $BACKEND_PID 2>/dev/null; then
success "Backend en cours d'exécution"
# Afficher les logs de démarrage
echo ""
echo "Logs de démarrage du backend:"
echo "─────────────────────────────"
tail -20 /tmp/backend.log
echo ""
# Vérifier le log DNS fix
if grep -q "Using direct IP" /tmp/backend.log; then
success "✨ DNS FIX DÉTECTÉ: Le backend utilise bien l'IP directe!"
else
warning "DNS fix non détecté dans les logs"
warning "Cela peut être normal si le message est tronqué"
fi
else
error "Le backend n'a pas démarré correctement"
echo ""
echo "Logs d'erreur:"
echo "──────────────"
cat /tmp/backend.log
exit 1
fi
# ============================================================
# ÉTAPE 5: Test de création de booking (optionnel)
# ============================================================
step_header "ÉTAPE 5/5: Instructions pour tester"
echo ""
echo "Le backend est maintenant en cours d'exécution avec les corrections."
echo ""
echo "Pour tester l'envoi d'email:"
echo "──────────────────────────────────────────────────────────────"
echo ""
echo "1. ${GREEN}Via le frontend${NC}:"
echo " - Ouvrez http://localhost:3000"
echo " - Créez un CSV booking"
echo " - Vérifiez les logs backend pour:"
echo " ${GREEN}✅ Email sent to carrier: <email>${NC}"
echo ""
echo "2. ${GREEN}Via l'API directement${NC}:"
echo " - Utilisez Postman ou curl"
echo " - POST http://localhost:4000/api/v1/csv-bookings"
echo " - Avec un fichier et les données du booking"
echo ""
echo "3. ${GREEN}Vérifier Mailtrap${NC}:"
echo " - https://mailtrap.io/inboxes"
echo " - Cherchez: 'Nouvelle demande de réservation'"
echo ""
echo "──────────────────────────────────────────────────────────────"
echo ""
info "Pour voir les logs backend en temps réel:"
echo " ${YELLOW}tail -f /tmp/backend.log${NC}"
echo ""
info "Pour arrêter le backend:"
echo " ${YELLOW}kill $BACKEND_PID${NC}"
echo ""
success "Diagnostic terminé!"
echo ""
echo "╔════════════════════════════════════════════════════════════╗"
echo "║ ✅ BACKEND PRÊT - Créez un booking pour tester ║"
echo "╚════════════════════════════════════════════════════════════╝"
echo ""