feat: refactor TFS integration structure and add scheduler functionality
- 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.
This commit is contained in:
@@ -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
|
||||
|
||||
85
src/app/api/tfs/scheduler-config/route.ts
Normal file
85
src/app/api/tfs/scheduler-config/route.ts
Normal file
@@ -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 });
|
||||
}
|
||||
}
|
||||
30
src/app/api/tfs/scheduler-status/route.ts
Normal file
30
src/app/api/tfs/scheduler-status/route.ts
Normal file
@@ -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 });
|
||||
}
|
||||
}
|
||||
@@ -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';
|
||||
|
||||
|
||||
@@ -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';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user