diff --git a/src/actions/tfs.ts b/src/actions/tfs.ts index e4567f7..7d2e428 100644 --- a/src/actions/tfs.ts +++ b/src/actions/tfs.ts @@ -2,7 +2,7 @@ import { userPreferencesService } from '@/services/core/user-preferences'; import { revalidatePath } from 'next/cache'; -import { tfsService, TfsConfig } from '@/services/integrations/tfs'; +import { tfsService, TfsConfig } from '@/services/integrations/tfs/tfs'; import { getServerSession } from 'next-auth'; import { authOptions } from '@/lib/auth'; diff --git a/src/app/api/tfs/delete-all/route.ts b/src/app/api/tfs/delete-all/route.ts index a329098..01aedb9 100644 --- a/src/app/api/tfs/delete-all/route.ts +++ b/src/app/api/tfs/delete-all/route.ts @@ -1,5 +1,5 @@ import { NextResponse } from 'next/server'; -import { tfsService } from '@/services/integrations/tfs'; +import { tfsService } from '@/services/integrations/tfs/tfs'; /** * Supprime toutes les tâches TFS de la base de données locale diff --git a/src/app/api/tfs/scheduler-config/route.ts b/src/app/api/tfs/scheduler-config/route.ts new file mode 100644 index 0000000..5989ccb --- /dev/null +++ b/src/app/api/tfs/scheduler-config/route.ts @@ -0,0 +1,85 @@ +import { NextRequest, NextResponse } from 'next/server'; +import { getServerSession } from 'next-auth'; +import { authOptions } from '@/lib/auth'; +import { userPreferencesService } from '@/services/core/user-preferences'; +import { tfsScheduler } from '@/services/integrations/tfs/scheduler'; + +/** + * GET /api/tfs/scheduler-config + * Récupère la configuration du scheduler TFS + */ +export async function GET() { + try { + const session = await getServerSession(authOptions); + if (!session?.user?.id) { + return NextResponse.json({ success: false, error: 'Non authentifié' }, { status: 401 }); + } + + const schedulerConfig = await userPreferencesService.getTfsSchedulerConfig(session.user.id); + + return NextResponse.json({ + success: true, + data: schedulerConfig + }); + } catch (error) { + console.error('Erreur récupération config scheduler TFS:', error); + return NextResponse.json({ + success: false, + error: error instanceof Error ? error.message : 'Erreur lors de la récupération' + }, { status: 500 }); + } +} + +/** + * POST /api/tfs/scheduler-config + * Sauvegarde la configuration du scheduler TFS + */ +export async function POST(request: NextRequest) { + try { + const session = await getServerSession(authOptions); + if (!session?.user?.id) { + return NextResponse.json({ success: false, error: 'Non authentifié' }, { status: 401 }); + } + + const body = await request.json(); + const { tfsAutoSync, tfsSyncInterval } = body; + + if (typeof tfsAutoSync !== 'boolean') { + return NextResponse.json({ + success: false, + error: 'tfsAutoSync doit être un booléen' + }, { status: 400 }); + } + + if (!['hourly', 'daily', 'weekly'].includes(tfsSyncInterval)) { + return NextResponse.json({ + success: false, + error: 'tfsSyncInterval doit être hourly, daily ou weekly' + }, { status: 400 }); + } + + await userPreferencesService.saveTfsSchedulerConfig( + session.user.id, + tfsAutoSync, + tfsSyncInterval + ); + + // Redémarrer le scheduler avec la nouvelle configuration + await tfsScheduler.restart(session.user.id); + + // Récupérer le statut mis à jour + const status = await tfsScheduler.getStatus(session.user.id); + + return NextResponse.json({ + success: true, + message: 'Configuration scheduler TFS mise à jour', + data: status + }); + } catch (error) { + console.error('Erreur sauvegarde config scheduler TFS:', error); + return NextResponse.json({ + success: false, + error: error instanceof Error ? error.message : 'Erreur lors de la sauvegarde' + }, { status: 500 }); + } +} diff --git a/src/app/api/tfs/scheduler-status/route.ts b/src/app/api/tfs/scheduler-status/route.ts new file mode 100644 index 0000000..ee4fa82 --- /dev/null +++ b/src/app/api/tfs/scheduler-status/route.ts @@ -0,0 +1,30 @@ +import { NextResponse } from 'next/server'; +import { getServerSession } from 'next-auth'; +import { authOptions } from '@/lib/auth'; +import { tfsScheduler } from '@/services/integrations/tfs/scheduler'; + +/** + * GET /api/tfs/scheduler-status + * Récupère le statut du scheduler TFS + */ +export async function GET() { + try { + const session = await getServerSession(authOptions); + if (!session?.user?.id) { + return NextResponse.json({ success: false, error: 'Non authentifié' }, { status: 401 }); + } + + const status = await tfsScheduler.getStatus(session.user.id); + + return NextResponse.json({ + success: true, + data: status + }); + } catch (error) { + console.error('Erreur récupération statut scheduler TFS:', error); + return NextResponse.json({ + success: false, + error: error instanceof Error ? error.message : 'Erreur lors de la récupération' + }, { status: 500 }); + } +} diff --git a/src/app/api/tfs/sync/route.ts b/src/app/api/tfs/sync/route.ts index d07dc9f..05f5e2e 100644 --- a/src/app/api/tfs/sync/route.ts +++ b/src/app/api/tfs/sync/route.ts @@ -1,5 +1,5 @@ import { NextResponse } from 'next/server'; -import { tfsService } from '@/services/integrations/tfs'; +import { tfsService } from '@/services/integrations/tfs/tfs'; import { getServerSession } from 'next-auth'; import { authOptions } from '@/lib/auth'; diff --git a/src/app/api/tfs/test/route.ts b/src/app/api/tfs/test/route.ts index 1313d0d..c67ae99 100644 --- a/src/app/api/tfs/test/route.ts +++ b/src/app/api/tfs/test/route.ts @@ -1,5 +1,5 @@ import { NextResponse } from 'next/server'; -import { tfsService } from '@/services/integrations/tfs'; +import { tfsService } from '@/services/integrations/tfs/tfs'; import { getServerSession } from 'next-auth'; import { authOptions } from '@/lib/auth'; diff --git a/src/components/forms/task/TaskTfsInfo.tsx b/src/components/forms/task/TaskTfsInfo.tsx index e8fe431..0c0664a 100644 --- a/src/components/forms/task/TaskTfsInfo.tsx +++ b/src/components/forms/task/TaskTfsInfo.tsx @@ -2,7 +2,7 @@ import { Badge } from '@/components/ui/Badge'; import { Task } from '@/lib/types'; -import { TfsConfig } from '@/services/integrations/tfs'; +import { TfsConfig } from '@/services/integrations/tfs/tfs'; import { useUserPreferences } from '@/contexts/UserPreferencesContext'; interface TaskTfsInfoProps { diff --git a/src/components/settings/IntegrationsSettingsPageClient.tsx b/src/components/settings/IntegrationsSettingsPageClient.tsx index 021e62c..3b841f7 100644 --- a/src/components/settings/IntegrationsSettingsPageClient.tsx +++ b/src/components/settings/IntegrationsSettingsPageClient.tsx @@ -1,15 +1,16 @@ 'use client'; import { JiraConfig } from '@/lib/types'; -import { TfsConfig } from '@/services/integrations/tfs'; +import { TfsConfig } from '@/services/integrations/tfs/tfs'; import { Header } from '@/components/ui/Header'; import { Card, CardHeader, CardContent } from '@/components/ui/Card'; -import { JiraConfigForm } from '@/components/settings/JiraConfigForm'; +import { JiraConfigForm } from './jira/JiraConfigForm'; import { JiraSync } from '@/components/jira/JiraSync'; import { JiraLogs } from '@/components/jira/JiraLogs'; import { JiraSchedulerConfig } from '@/components/jira/JiraSchedulerConfig'; -import { TfsConfigForm } from '@/components/settings/TfsConfigForm'; -import { TfsSync } from '@/components/tfs/TfsSync'; +import { TfsConfigForm } from './tfs/TfsConfigForm'; +import { TfsSync } from './tfs/TfsSync'; +import { TfsSchedulerConfig } from './tfs/TfsSchedulerConfig'; import Link from 'next/link'; interface IntegrationsSettingsPageClientProps { @@ -154,7 +155,10 @@ export function IntegrationsSettingsPageClient({ {/* Actions TFS */}