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:
@@ -12,8 +12,9 @@ async function testJiraFields() {
|
|||||||
console.log('🔍 Identification des champs personnalisés Jira\n');
|
console.log('🔍 Identification des champs personnalisés Jira\n');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Récupérer la config Jira
|
// Récupérer la config Jira pour l'utilisateur spécifié ou 'default'
|
||||||
const jiraConfig = await userPreferencesService.getJiraConfig('default');
|
const userId = process.argv[2] || 'default';
|
||||||
|
const jiraConfig = await userPreferencesService.getJiraConfig(userId);
|
||||||
|
|
||||||
if (!jiraConfig.enabled || !jiraConfig.baseUrl || !jiraConfig.email || !jiraConfig.apiToken) {
|
if (!jiraConfig.enabled || !jiraConfig.baseUrl || !jiraConfig.email || !jiraConfig.apiToken) {
|
||||||
console.log('❌ Configuration Jira manquante');
|
console.log('❌ Configuration Jira manquante');
|
||||||
|
|||||||
@@ -12,8 +12,9 @@ async function testStoryPoints() {
|
|||||||
console.log('🧪 Test de récupération des story points Jira\n');
|
console.log('🧪 Test de récupération des story points Jira\n');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Récupérer la config Jira
|
// Récupérer la config Jira pour l'utilisateur spécifié ou 'default'
|
||||||
const jiraConfig = await userPreferencesService.getJiraConfig('default');
|
const userId = process.argv[2] || 'default';
|
||||||
|
const jiraConfig = await userPreferencesService.getJiraConfig(userId);
|
||||||
|
|
||||||
if (!jiraConfig.enabled || !jiraConfig.baseUrl || !jiraConfig.email || !jiraConfig.apiToken) {
|
if (!jiraConfig.enabled || !jiraConfig.baseUrl || !jiraConfig.email || !jiraConfig.apiToken) {
|
||||||
console.log('❌ Configuration Jira manquante');
|
console.log('❌ Configuration Jira manquante');
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
import { NextResponse } from 'next/server';
|
import { NextResponse } from 'next/server';
|
||||||
import { tfsService } from '@/services/integrations/tfs';
|
import { tfsService } from '@/services/integrations/tfs';
|
||||||
|
import { getServerSession } from 'next-auth';
|
||||||
|
import { authOptions } from '@/lib/auth';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Route POST /api/tfs/sync
|
* Route POST /api/tfs/sync
|
||||||
@@ -8,10 +10,18 @@ import { tfsService } from '@/services/integrations/tfs';
|
|||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
export async function POST(_request: Request) {
|
export async function POST(_request: Request) {
|
||||||
try {
|
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...');
|
console.log('🔄 Début de la synchronisation TFS manuelle...');
|
||||||
|
|
||||||
// Effectuer la synchronisation via le service singleton
|
// Effectuer la synchronisation via le service singleton avec l'utilisateur connecté
|
||||||
const result = await tfsService.syncTasks();
|
const result = await tfsService.syncTasks(session.user.id);
|
||||||
|
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
return NextResponse.json({
|
return NextResponse.json({
|
||||||
@@ -46,8 +56,16 @@ export async function POST(_request: Request) {
|
|||||||
*/
|
*/
|
||||||
export async function GET() {
|
export async function GET() {
|
||||||
try {
|
try {
|
||||||
// Tester la connexion via le service singleton
|
const session = await getServerSession(authOptions);
|
||||||
const isConnected = await tfsService.testConnection();
|
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) {
|
if (isConnected) {
|
||||||
return NextResponse.json({
|
return NextResponse.json({
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
import { NextResponse } from 'next/server';
|
import { NextResponse } from 'next/server';
|
||||||
import { tfsService } from '@/services/integrations/tfs';
|
import { tfsService } from '@/services/integrations/tfs';
|
||||||
|
import { getServerSession } from 'next-auth';
|
||||||
|
import { authOptions } from '@/lib/auth';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Route GET /api/tfs/test
|
* Route GET /api/tfs/test
|
||||||
@@ -7,10 +9,18 @@ import { tfsService } from '@/services/integrations/tfs';
|
|||||||
*/
|
*/
|
||||||
export async function GET() {
|
export async function GET() {
|
||||||
try {
|
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...');
|
console.log('🔄 Test de connexion TFS...');
|
||||||
|
|
||||||
// Valider la configuration via le service singleton
|
// Valider la configuration via le service singleton avec l'utilisateur connecté
|
||||||
const configValidation = await tfsService.validateConfig();
|
const configValidation = await tfsService.validateConfig(session.user.id);
|
||||||
if (!configValidation.valid) {
|
if (!configValidation.valid) {
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
{
|
{
|
||||||
@@ -22,8 +32,8 @@ export async function GET() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tester la connexion
|
// Tester la connexion avec l'utilisateur connecté
|
||||||
const isConnected = await tfsService.testConnection();
|
const isConnected = await tfsService.testConnection(session.user.id);
|
||||||
|
|
||||||
if (isConnected) {
|
if (isConnected) {
|
||||||
// Test approfondi : récupérer des métadonnées
|
// 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
|
super({ enabled: false }); // Config vide par défaut
|
||||||
}
|
}
|
||||||
|
|
||||||
private async getConfig(): Promise<TfsConfig> {
|
private async getConfig(userId?: string): Promise<TfsConfig> {
|
||||||
const userConfig = await userPreferencesService.getTfsConfig('default');
|
const targetUserId = userId || 'default';
|
||||||
|
const userConfig = await userPreferencesService.getTfsConfig(targetUserId);
|
||||||
return userConfig;
|
return userConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
async testConnection(): Promise<boolean> {
|
async testConnection(userId?: string): Promise<boolean> {
|
||||||
const config = await this.getConfig();
|
const config = await this.getConfig(userId);
|
||||||
if (!config.enabled || !config.organizationUrl || !config.personalAccessToken) {
|
if (!config.enabled || !config.organizationUrl || !config.personalAccessToken) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -1068,14 +1069,14 @@ class TfsServiceInstance extends TfsService {
|
|||||||
return service.testConnection();
|
return service.testConnection();
|
||||||
}
|
}
|
||||||
|
|
||||||
async validateConfig(): Promise<{ valid: boolean; error?: string }> {
|
async validateConfig(userId?: string): Promise<{ valid: boolean; error?: string }> {
|
||||||
const config = await this.getConfig();
|
const config = await this.getConfig(userId);
|
||||||
const service = new TfsService(config);
|
const service = new TfsService(config);
|
||||||
return service.validateConfig();
|
return service.validateConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
async syncTasks(): Promise<TfsSyncResult> {
|
async syncTasks(userId?: string): Promise<TfsSyncResult> {
|
||||||
const config = await this.getConfig();
|
const config = await this.getConfig(userId);
|
||||||
const service = new TfsService(config);
|
const service = new TfsService(config);
|
||||||
return service.syncTasks();
|
return service.syncTasks();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user