- Introduced a new structure for services in `src/services/` to improve organization by domain, including core, analytics, data management, integrations, and task management. - Moved relevant files to their new locations and updated all internal and external imports accordingly. - Updated `TODO.md` to reflect the new service organization and outlined phases for further refactoring.
71 lines
2.1 KiB
TypeScript
71 lines
2.1 KiB
TypeScript
import { NextRequest, NextResponse } from 'next/server';
|
|
import { createJiraService } from '@/services/jira';
|
|
import { userPreferencesService } from '@/services/core/user-preferences';
|
|
|
|
/**
|
|
* POST /api/jira/validate-project
|
|
* Valide l'existence d'un projet Jira
|
|
*/
|
|
export async function POST(request: NextRequest) {
|
|
try {
|
|
const body = await request.json();
|
|
const { projectKey } = body;
|
|
|
|
if (!projectKey || typeof projectKey !== 'string') {
|
|
return NextResponse.json(
|
|
{ error: 'projectKey est requis' },
|
|
{ status: 400 }
|
|
);
|
|
}
|
|
|
|
// Récupérer la config Jira depuis la base de données
|
|
const jiraConfig = await userPreferencesService.getJiraConfig();
|
|
|
|
if (!jiraConfig.enabled || !jiraConfig.baseUrl || !jiraConfig.email || !jiraConfig.apiToken) {
|
|
return NextResponse.json(
|
|
{ error: 'Configuration Jira manquante. Configurez Jira dans les paramètres.' },
|
|
{ status: 400 }
|
|
);
|
|
}
|
|
|
|
// Créer le service Jira
|
|
const jiraService = createJiraService();
|
|
if (!jiraService) {
|
|
return NextResponse.json(
|
|
{ error: 'Impossible de créer le service Jira. Vérifiez la configuration.' },
|
|
{ status: 500 }
|
|
);
|
|
}
|
|
|
|
// Valider le projet
|
|
const validation = await jiraService.validateProject(projectKey.trim().toUpperCase());
|
|
|
|
if (validation.exists) {
|
|
return NextResponse.json({
|
|
success: true,
|
|
exists: true,
|
|
projectName: validation.name,
|
|
message: `Projet "${projectKey}" trouvé : ${validation.name}`
|
|
});
|
|
} else {
|
|
return NextResponse.json({
|
|
success: false,
|
|
exists: false,
|
|
error: validation.error,
|
|
message: validation.error || `Projet "${projectKey}" introuvable`
|
|
}, { status: 404 });
|
|
}
|
|
|
|
} catch (error) {
|
|
console.error('Erreur lors de la validation du projet Jira:', error);
|
|
return NextResponse.json(
|
|
{
|
|
success: false,
|
|
error: 'Erreur lors de la validation du projet',
|
|
message: error instanceof Error ? error.message : 'Erreur inconnue'
|
|
},
|
|
{ status: 500 }
|
|
);
|
|
}
|
|
}
|