feat: enhance TFS and Jira field tests with user-specific configurations
- Updated `testJiraFields` and `testStoryPoints` to accept a `userId` from command line arguments, allowing for user-specific Jira configurations. - Modified TFS sync and test routes to include user authentication checks and pass the logged-in user's ID for task synchronization and connection testing. - Refactored `TfsService` methods to utilize user-specific configurations, improving flexibility and accuracy in TFS operations.
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
import { tfsService } from '@/services/integrations/tfs';
|
||||
import { getServerSession } from 'next-auth';
|
||||
import { authOptions } from '@/lib/auth';
|
||||
|
||||
/**
|
||||
* Route POST /api/tfs/sync
|
||||
@@ -8,10 +10,18 @@ import { tfsService } from '@/services/integrations/tfs';
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
export async function POST(_request: Request) {
|
||||
try {
|
||||
const session = await getServerSession(authOptions);
|
||||
if (!session?.user?.id) {
|
||||
return NextResponse.json(
|
||||
{ success: false, error: 'Non authentifié' },
|
||||
{ status: 401 }
|
||||
);
|
||||
}
|
||||
|
||||
console.log('🔄 Début de la synchronisation TFS manuelle...');
|
||||
|
||||
// Effectuer la synchronisation via le service singleton
|
||||
const result = await tfsService.syncTasks();
|
||||
// Effectuer la synchronisation via le service singleton avec l'utilisateur connecté
|
||||
const result = await tfsService.syncTasks(session.user.id);
|
||||
|
||||
if (result.success) {
|
||||
return NextResponse.json({
|
||||
@@ -46,8 +56,16 @@ export async function POST(_request: Request) {
|
||||
*/
|
||||
export async function GET() {
|
||||
try {
|
||||
// Tester la connexion via le service singleton
|
||||
const isConnected = await tfsService.testConnection();
|
||||
const session = await getServerSession(authOptions);
|
||||
if (!session?.user?.id) {
|
||||
return NextResponse.json(
|
||||
{ success: false, error: 'Non authentifié' },
|
||||
{ status: 401 }
|
||||
);
|
||||
}
|
||||
|
||||
// Tester la connexion via le service singleton avec l'utilisateur connecté
|
||||
const isConnected = await tfsService.testConnection(session.user.id);
|
||||
|
||||
if (isConnected) {
|
||||
return NextResponse.json({
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
import { tfsService } from '@/services/integrations/tfs';
|
||||
import { getServerSession } from 'next-auth';
|
||||
import { authOptions } from '@/lib/auth';
|
||||
|
||||
/**
|
||||
* Route GET /api/tfs/test
|
||||
@@ -7,10 +9,18 @@ import { tfsService } from '@/services/integrations/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 }
|
||||
);
|
||||
}
|
||||
|
||||
console.log('🔄 Test de connexion TFS...');
|
||||
|
||||
// Valider la configuration via le service singleton
|
||||
const configValidation = await tfsService.validateConfig();
|
||||
// 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(
|
||||
{
|
||||
@@ -22,8 +32,8 @@ export async function GET() {
|
||||
);
|
||||
}
|
||||
|
||||
// Tester la connexion
|
||||
const isConnected = await tfsService.testConnection();
|
||||
// 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
|
||||
|
||||
@@ -1053,13 +1053,14 @@ class TfsServiceInstance extends TfsService {
|
||||
super({ enabled: false }); // Config vide par défaut
|
||||
}
|
||||
|
||||
private async getConfig(): Promise<TfsConfig> {
|
||||
const userConfig = await userPreferencesService.getTfsConfig('default');
|
||||
private async getConfig(userId?: string): Promise<TfsConfig> {
|
||||
const targetUserId = userId || 'default';
|
||||
const userConfig = await userPreferencesService.getTfsConfig(targetUserId);
|
||||
return userConfig;
|
||||
}
|
||||
|
||||
async testConnection(): Promise<boolean> {
|
||||
const config = await this.getConfig();
|
||||
async testConnection(userId?: string): Promise<boolean> {
|
||||
const config = await this.getConfig(userId);
|
||||
if (!config.enabled || !config.organizationUrl || !config.personalAccessToken) {
|
||||
return false;
|
||||
}
|
||||
@@ -1068,14 +1069,14 @@ class TfsServiceInstance extends TfsService {
|
||||
return service.testConnection();
|
||||
}
|
||||
|
||||
async validateConfig(): Promise<{ valid: boolean; error?: string }> {
|
||||
const config = await this.getConfig();
|
||||
async validateConfig(userId?: string): Promise<{ valid: boolean; error?: string }> {
|
||||
const config = await this.getConfig(userId);
|
||||
const service = new TfsService(config);
|
||||
return service.validateConfig();
|
||||
}
|
||||
|
||||
async syncTasks(): Promise<TfsSyncResult> {
|
||||
const config = await this.getConfig();
|
||||
async syncTasks(userId?: string): Promise<TfsSyncResult> {
|
||||
const config = await this.getConfig(userId);
|
||||
const service = new TfsService(config);
|
||||
return service.syncTasks();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user