feat: implement Jira auto-sync scheduler and UI configuration
- Added `jiraAutoSync` and `jiraSyncInterval` fields to user preferences for scheduler configuration. - Created `JiraScheduler` service to manage automatic synchronization with Jira based on user settings. - Updated API route to handle scheduler actions and configuration updates. - Introduced `JiraSchedulerConfig` component for user interface to control scheduler settings. - Enhanced `TODO.md` to reflect completed tasks related to Jira synchronization features.
This commit is contained in:
@@ -30,7 +30,9 @@ const DEFAULT_PREFERENCES: UserPreferences = {
|
||||
email: '',
|
||||
apiToken: '',
|
||||
ignoredProjects: []
|
||||
}
|
||||
},
|
||||
jiraAutoSync: false,
|
||||
jiraSyncInterval: 'daily'
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -56,9 +58,29 @@ class UserPreferencesService {
|
||||
}
|
||||
});
|
||||
|
||||
// S'assurer que les nouveaux champs existent (migration douce)
|
||||
await this.ensureJiraSchedulerFields();
|
||||
|
||||
return userPrefs;
|
||||
}
|
||||
|
||||
/**
|
||||
* S'assure que les champs jiraAutoSync et jiraSyncInterval existent
|
||||
*/
|
||||
private async ensureJiraSchedulerFields(): Promise<void> {
|
||||
try {
|
||||
await prisma.$executeRaw`
|
||||
UPDATE user_preferences
|
||||
SET jiraAutoSync = COALESCE(jiraAutoSync, ${DEFAULT_PREFERENCES.jiraAutoSync}),
|
||||
jiraSyncInterval = COALESCE(jiraSyncInterval, ${DEFAULT_PREFERENCES.jiraSyncInterval})
|
||||
WHERE id = 'default'
|
||||
`;
|
||||
} catch (error) {
|
||||
// Ignorer les erreurs si les colonnes n'existent pas encore
|
||||
console.debug('Migration douce des champs scheduler Jira:', error);
|
||||
}
|
||||
}
|
||||
|
||||
// === FILTRES KANBAN ===
|
||||
|
||||
/**
|
||||
@@ -216,22 +238,76 @@ class UserPreferencesService {
|
||||
}
|
||||
}
|
||||
|
||||
// === CONFIGURATION SCHEDULER JIRA ===
|
||||
|
||||
/**
|
||||
* Sauvegarde les préférences du scheduler Jira
|
||||
*/
|
||||
async saveJiraSchedulerConfig(jiraAutoSync: boolean, jiraSyncInterval: 'hourly' | 'daily' | 'weekly'): Promise<void> {
|
||||
try {
|
||||
const userPrefs = await this.getOrCreateUserPreferences();
|
||||
// Utiliser une requête SQL brute temporairement pour éviter les problèmes de types
|
||||
await prisma.$executeRaw`
|
||||
UPDATE user_preferences
|
||||
SET jiraAutoSync = ${jiraAutoSync}, jiraSyncInterval = ${jiraSyncInterval}
|
||||
WHERE id = ${userPrefs.id}
|
||||
`;
|
||||
} catch (error) {
|
||||
console.warn('Erreur lors de la sauvegarde de la config scheduler Jira:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Récupère les préférences du scheduler Jira
|
||||
*/
|
||||
async getJiraSchedulerConfig(): Promise<{ jiraAutoSync: boolean; jiraSyncInterval: 'hourly' | 'daily' | 'weekly' }> {
|
||||
try {
|
||||
const userPrefs = await this.getOrCreateUserPreferences();
|
||||
// Utiliser une requête SQL brute pour récupérer les nouveaux champs
|
||||
const result = await prisma.$queryRaw<Array<{ jiraAutoSync: number; jiraSyncInterval: string }>>`
|
||||
SELECT jiraAutoSync, jiraSyncInterval FROM user_preferences WHERE id = ${userPrefs.id}
|
||||
`;
|
||||
|
||||
if (result.length > 0) {
|
||||
return {
|
||||
jiraAutoSync: Boolean(result[0].jiraAutoSync),
|
||||
jiraSyncInterval: (result[0].jiraSyncInterval as 'hourly' | 'daily' | 'weekly') || DEFAULT_PREFERENCES.jiraSyncInterval
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
jiraAutoSync: DEFAULT_PREFERENCES.jiraAutoSync,
|
||||
jiraSyncInterval: DEFAULT_PREFERENCES.jiraSyncInterval
|
||||
};
|
||||
} catch (error) {
|
||||
console.warn('Erreur lors de la récupération de la config scheduler Jira:', error);
|
||||
return {
|
||||
jiraAutoSync: DEFAULT_PREFERENCES.jiraAutoSync,
|
||||
jiraSyncInterval: DEFAULT_PREFERENCES.jiraSyncInterval
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Récupère toutes les préférences utilisateur
|
||||
*/
|
||||
async getAllPreferences(): Promise<UserPreferences> {
|
||||
const [kanbanFilters, viewPreferences, columnVisibility, jiraConfig] = await Promise.all([
|
||||
const [kanbanFilters, viewPreferences, columnVisibility, jiraConfig, jiraSchedulerConfig] = await Promise.all([
|
||||
this.getKanbanFilters(),
|
||||
this.getViewPreferences(),
|
||||
this.getColumnVisibility(),
|
||||
this.getJiraConfig()
|
||||
this.getJiraConfig(),
|
||||
this.getJiraSchedulerConfig()
|
||||
]);
|
||||
|
||||
return {
|
||||
kanbanFilters,
|
||||
viewPreferences,
|
||||
columnVisibility,
|
||||
jiraConfig
|
||||
jiraConfig,
|
||||
jiraAutoSync: jiraSchedulerConfig.jiraAutoSync,
|
||||
jiraSyncInterval: jiraSchedulerConfig.jiraSyncInterval
|
||||
};
|
||||
}
|
||||
|
||||
@@ -243,7 +319,8 @@ class UserPreferencesService {
|
||||
this.saveKanbanFilters(preferences.kanbanFilters),
|
||||
this.saveViewPreferences(preferences.viewPreferences),
|
||||
this.saveColumnVisibility(preferences.columnVisibility),
|
||||
this.saveJiraConfig(preferences.jiraConfig)
|
||||
this.saveJiraConfig(preferences.jiraConfig),
|
||||
this.saveJiraSchedulerConfig(preferences.jiraAutoSync, preferences.jiraSyncInterval)
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user