- Updated TFS service imports to a new directory structure for better organization. - Introduced new API routes for TFS scheduler configuration and status retrieval. - Implemented TFS scheduler logic to manage automatic synchronization based on user preferences. - Added components for TFS configuration and scheduler management, enhancing user interaction with TFS settings. - Removed deprecated TfsSync component, consolidating functionality into the new structure.
82 lines
2.4 KiB
TypeScript
82 lines
2.4 KiB
TypeScript
import { NextResponse } from 'next/server';
|
|
import { tfsService } from '@/services/integrations/tfs/tfs';
|
|
import { getServerSession } from 'next-auth';
|
|
import { authOptions } from '@/lib/auth';
|
|
|
|
/**
|
|
* Route GET /api/tfs/test
|
|
* Teste uniquement la connexion TFS/Azure DevOps sans effectuer de synchronisation
|
|
*/
|
|
export async function GET() {
|
|
try {
|
|
const session = await getServerSession(authOptions);
|
|
if (!session?.user?.id) {
|
|
return NextResponse.json(
|
|
{ success: false, error: 'Non authentifié' },
|
|
{ status: 401 }
|
|
);
|
|
}
|
|
|
|
console.log('🔄 Test de connexion TFS...');
|
|
|
|
// Valider la configuration via le service singleton avec l'utilisateur connecté
|
|
const configValidation = await tfsService.validateConfig(session.user.id);
|
|
if (!configValidation.valid) {
|
|
return NextResponse.json(
|
|
{
|
|
error: 'Configuration TFS invalide',
|
|
connected: false,
|
|
details: configValidation.error,
|
|
},
|
|
{ status: 400 }
|
|
);
|
|
}
|
|
|
|
// Tester la connexion avec l'utilisateur connecté
|
|
const isConnected = await tfsService.testConnection(session.user.id);
|
|
|
|
if (isConnected) {
|
|
// Test approfondi : récupérer des métadonnées
|
|
try {
|
|
const repositories = await tfsService.getMetadata();
|
|
return NextResponse.json({
|
|
message: 'Connexion Azure DevOps réussie',
|
|
connected: true,
|
|
details: {
|
|
repositoriesCount: repositories.repositories.length,
|
|
},
|
|
});
|
|
} catch (repoError) {
|
|
return NextResponse.json(
|
|
{
|
|
error: 'Connexion OK mais accès aux repositories limité',
|
|
connected: false,
|
|
details: `Vérifiez les permissions du token PAT: ${repoError instanceof Error ? repoError.message : 'Erreur inconnue'}`,
|
|
},
|
|
{ status: 403 }
|
|
);
|
|
}
|
|
} else {
|
|
return NextResponse.json(
|
|
{
|
|
error: 'Connexion Azure DevOps échouée',
|
|
connected: false,
|
|
details: "Vérifiez l'URL d'organisation et le token PAT",
|
|
},
|
|
{ status: 401 }
|
|
);
|
|
}
|
|
} catch (error) {
|
|
console.error('❌ Erreur test connexion TFS:', error);
|
|
|
|
return NextResponse.json(
|
|
{
|
|
error: 'Erreur interne',
|
|
connected: false,
|
|
details: error instanceof Error ? error.message : 'Erreur inconnue',
|
|
},
|
|
{ status: 500 }
|
|
);
|
|
}
|
|
}
|