chore: prettier everywhere
This commit is contained in:
@@ -21,7 +21,9 @@ export class BackupClient {
|
||||
* Liste toutes les sauvegardes disponibles et l'état du scheduler
|
||||
*/
|
||||
async listBackups(): Promise<BackupListResponse> {
|
||||
const response = await httpClient.get<{ data: BackupListResponse }>(this.baseUrl);
|
||||
const response = await httpClient.get<{ data: BackupListResponse }>(
|
||||
this.baseUrl
|
||||
);
|
||||
return response.data;
|
||||
}
|
||||
|
||||
@@ -29,15 +31,19 @@ export class BackupClient {
|
||||
* Crée une nouvelle sauvegarde manuelle
|
||||
*/
|
||||
async createBackup(force: boolean = false): Promise<BackupInfo | null> {
|
||||
const response = await httpClient.post<{ data?: BackupInfo; skipped?: boolean; message?: string }>(this.baseUrl, {
|
||||
const response = await httpClient.post<{
|
||||
data?: BackupInfo;
|
||||
skipped?: boolean;
|
||||
message?: string;
|
||||
}>(this.baseUrl, {
|
||||
action: 'create',
|
||||
force
|
||||
force,
|
||||
});
|
||||
|
||||
|
||||
if (response.skipped) {
|
||||
return null; // Backup was skipped
|
||||
}
|
||||
|
||||
|
||||
return response.data!;
|
||||
}
|
||||
|
||||
@@ -46,7 +52,7 @@ export class BackupClient {
|
||||
*/
|
||||
async verifyDatabase(): Promise<void> {
|
||||
await httpClient.post(this.baseUrl, {
|
||||
action: 'verify'
|
||||
action: 'verify',
|
||||
});
|
||||
}
|
||||
|
||||
@@ -54,10 +60,13 @@ export class BackupClient {
|
||||
* Met à jour la configuration des sauvegardes
|
||||
*/
|
||||
async updateConfig(config: Partial<BackupConfig>): Promise<BackupConfig> {
|
||||
const response = await httpClient.post<{ data: BackupConfig }>(this.baseUrl, {
|
||||
action: 'config',
|
||||
config
|
||||
});
|
||||
const response = await httpClient.post<{ data: BackupConfig }>(
|
||||
this.baseUrl,
|
||||
{
|
||||
action: 'config',
|
||||
config,
|
||||
}
|
||||
);
|
||||
return response.data;
|
||||
}
|
||||
|
||||
@@ -72,16 +81,18 @@ export class BackupClient {
|
||||
maxBackups: number;
|
||||
backupPath: string;
|
||||
}> {
|
||||
const response = await httpClient.post<{ data: {
|
||||
isRunning: boolean;
|
||||
isEnabled: boolean;
|
||||
interval: string;
|
||||
nextBackup: string | null;
|
||||
maxBackups: number;
|
||||
backupPath: string;
|
||||
} }>(this.baseUrl, {
|
||||
const response = await httpClient.post<{
|
||||
data: {
|
||||
isRunning: boolean;
|
||||
isEnabled: boolean;
|
||||
interval: string;
|
||||
nextBackup: string | null;
|
||||
maxBackups: number;
|
||||
backupPath: string;
|
||||
};
|
||||
}>(this.baseUrl, {
|
||||
action: 'scheduler',
|
||||
enabled
|
||||
enabled,
|
||||
});
|
||||
return response.data;
|
||||
}
|
||||
@@ -98,7 +109,7 @@ export class BackupClient {
|
||||
*/
|
||||
async restoreBackup(filename: string): Promise<void> {
|
||||
await httpClient.post(`${this.baseUrl}/${filename}`, {
|
||||
action: 'restore'
|
||||
action: 'restore',
|
||||
});
|
||||
}
|
||||
|
||||
@@ -106,25 +117,31 @@ export class BackupClient {
|
||||
* Récupère les logs de backup
|
||||
*/
|
||||
async getBackupLogs(maxLines: number = 100): Promise<string[]> {
|
||||
const response = await httpClient.get<{ data: { logs: string[] } }>(`${this.baseUrl}?action=logs&maxLines=${maxLines}`);
|
||||
const response = await httpClient.get<{ data: { logs: string[] } }>(
|
||||
`${this.baseUrl}?action=logs&maxLines=${maxLines}`
|
||||
);
|
||||
return response.data.logs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Récupère les statistiques de sauvegarde par jour
|
||||
*/
|
||||
async getBackupStats(days: number = 30): Promise<Array<{
|
||||
date: string;
|
||||
manual: number;
|
||||
automatic: number;
|
||||
total: number;
|
||||
}>> {
|
||||
const response = await httpClient.get<{ data: Array<{
|
||||
async getBackupStats(days: number = 30): Promise<
|
||||
Array<{
|
||||
date: string;
|
||||
manual: number;
|
||||
automatic: number;
|
||||
total: number;
|
||||
}> }>(`${this.baseUrl}?action=stats&days=${days}`);
|
||||
}>
|
||||
> {
|
||||
const response = await httpClient.get<{
|
||||
data: Array<{
|
||||
date: string;
|
||||
manual: number;
|
||||
automatic: number;
|
||||
total: number;
|
||||
}>;
|
||||
}>(`${this.baseUrl}?action=stats&days=${days}`);
|
||||
return response.data;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ export class HttpClient {
|
||||
options: RequestInit = {}
|
||||
): Promise<T> {
|
||||
const url = `${this.baseUrl}${endpoint}`;
|
||||
|
||||
|
||||
const config: RequestInit = {
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
@@ -24,10 +24,12 @@ export class HttpClient {
|
||||
|
||||
try {
|
||||
const response = await fetch(url, config);
|
||||
|
||||
|
||||
if (!response.ok) {
|
||||
const errorData = await response.json().catch(() => ({}));
|
||||
throw new Error(errorData.error || `HTTP ${response.status}: ${response.statusText}`);
|
||||
throw new Error(
|
||||
errorData.error || `HTTP ${response.status}: ${response.statusText}`
|
||||
);
|
||||
}
|
||||
|
||||
return await response.json();
|
||||
@@ -38,10 +40,10 @@ export class HttpClient {
|
||||
}
|
||||
|
||||
async get<T>(endpoint: string, params?: Record<string, string>): Promise<T> {
|
||||
const url = params
|
||||
const url = params
|
||||
? `${endpoint}?${new URLSearchParams(params)}`
|
||||
: endpoint;
|
||||
|
||||
|
||||
return this.request<T>(url, { method: 'GET' });
|
||||
}
|
||||
|
||||
@@ -66,11 +68,14 @@ export class HttpClient {
|
||||
});
|
||||
}
|
||||
|
||||
async delete<T>(endpoint: string, params?: Record<string, string>): Promise<T> {
|
||||
const url = params
|
||||
async delete<T>(
|
||||
endpoint: string,
|
||||
params?: Record<string, string>
|
||||
): Promise<T> {
|
||||
const url = params
|
||||
? `${endpoint}?${new URLSearchParams(params)}`
|
||||
: endpoint;
|
||||
|
||||
|
||||
return this.request<T>(url, { method: 'DELETE' });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,12 @@
|
||||
import { httpClient } from './base/http-client';
|
||||
import { DailyCheckbox, DailyView, Task } from '@/lib/types';
|
||||
import { formatDateForAPI, parseDate, getToday, addDays, subtractDays } from '@/lib/date-utils';
|
||||
import {
|
||||
formatDateForAPI,
|
||||
parseDate,
|
||||
getToday,
|
||||
addDays,
|
||||
subtractDays,
|
||||
} from '@/lib/date-utils';
|
||||
|
||||
// Types pour les réponses API (avec dates en string)
|
||||
interface ApiCheckbox {
|
||||
@@ -67,29 +73,35 @@ export class DailyClient {
|
||||
/**
|
||||
* Récupère l'historique des checkboxes
|
||||
*/
|
||||
async getCheckboxHistory(filters?: DailyHistoryFilters): Promise<{ date: Date; checkboxes: DailyCheckbox[] }[]> {
|
||||
async getCheckboxHistory(
|
||||
filters?: DailyHistoryFilters
|
||||
): Promise<{ date: Date; checkboxes: DailyCheckbox[] }[]> {
|
||||
const params = new URLSearchParams({ action: 'history' });
|
||||
|
||||
|
||||
if (filters?.limit) params.append('limit', filters.limit.toString());
|
||||
|
||||
|
||||
const result = await httpClient.get<ApiHistoryItem[]>(`/daily?${params}`);
|
||||
return result.map(item => ({
|
||||
return result.map((item) => ({
|
||||
date: parseDate(item.date),
|
||||
checkboxes: item.checkboxes.map((cb: ApiCheckbox) => this.transformCheckboxDates(cb))
|
||||
checkboxes: item.checkboxes.map((cb: ApiCheckbox) =>
|
||||
this.transformCheckboxDates(cb)
|
||||
),
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* Recherche dans les checkboxes
|
||||
*/
|
||||
async searchCheckboxes(filters: DailySearchFilters): Promise<DailyCheckbox[]> {
|
||||
async searchCheckboxes(
|
||||
filters: DailySearchFilters
|
||||
): Promise<DailyCheckbox[]> {
|
||||
const params = new URLSearchParams({
|
||||
action: 'search',
|
||||
q: filters.query
|
||||
q: filters.query,
|
||||
});
|
||||
|
||||
|
||||
if (filters.limit) params.append('limit', filters.limit.toString());
|
||||
|
||||
|
||||
const result = await httpClient.get<ApiCheckbox[]>(`/daily?${params}`);
|
||||
return result.map((cb: ApiCheckbox) => this.transformCheckboxDates(cb));
|
||||
}
|
||||
@@ -110,7 +122,7 @@ export class DailyClient {
|
||||
date: parseDate(checkbox.date),
|
||||
createdAt: parseDate(checkbox.createdAt),
|
||||
updatedAt: parseDate(checkbox.updatedAt),
|
||||
isArchived: checkbox.text.includes('[ARCHIVÉ]')
|
||||
isArchived: checkbox.text.includes('[ARCHIVÉ]'),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -120,17 +132,23 @@ export class DailyClient {
|
||||
private transformDailyViewDates(view: ApiDailyView): DailyView {
|
||||
return {
|
||||
date: parseDate(view.date),
|
||||
yesterday: view.yesterday.map((cb: ApiCheckbox) => this.transformCheckboxDates(cb)),
|
||||
today: view.today.map((cb: ApiCheckbox) => this.transformCheckboxDates(cb))
|
||||
yesterday: view.yesterday.map((cb: ApiCheckbox) =>
|
||||
this.transformCheckboxDates(cb)
|
||||
),
|
||||
today: view.today.map((cb: ApiCheckbox) =>
|
||||
this.transformCheckboxDates(cb)
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Récupère la vue daily d'une date relative (hier, aujourd'hui, demain)
|
||||
*/
|
||||
async getDailyViewByRelativeDate(relative: 'yesterday' | 'today' | 'tomorrow'): Promise<DailyView> {
|
||||
async getDailyViewByRelativeDate(
|
||||
relative: 'yesterday' | 'today' | 'tomorrow'
|
||||
): Promise<DailyView> {
|
||||
let date: Date;
|
||||
|
||||
|
||||
switch (relative) {
|
||||
case 'yesterday':
|
||||
date = subtractDays(getToday(), 1);
|
||||
@@ -143,7 +161,7 @@ export class DailyClient {
|
||||
date = getToday();
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
return this.getDailyView(date);
|
||||
}
|
||||
|
||||
@@ -166,12 +184,15 @@ export class DailyClient {
|
||||
}): Promise<DailyCheckbox[]> {
|
||||
const params = new URLSearchParams();
|
||||
if (options?.maxDays) params.append('maxDays', options.maxDays.toString());
|
||||
if (options?.excludeToday !== undefined) params.append('excludeToday', options.excludeToday.toString());
|
||||
if (options?.excludeToday !== undefined)
|
||||
params.append('excludeToday', options.excludeToday.toString());
|
||||
if (options?.type) params.append('type', options.type);
|
||||
if (options?.limit) params.append('limit', options.limit.toString());
|
||||
|
||||
|
||||
const queryString = params.toString();
|
||||
const result = await httpClient.get<ApiCheckbox[]>(`/daily/pending${queryString ? `?${queryString}` : ''}`);
|
||||
const result = await httpClient.get<ApiCheckbox[]>(
|
||||
`/daily/pending${queryString ? `?${queryString}` : ''}`
|
||||
);
|
||||
return result.map((cb: ApiCheckbox) => this.transformCheckboxDates(cb));
|
||||
}
|
||||
|
||||
@@ -179,10 +200,12 @@ export class DailyClient {
|
||||
* Archive une checkbox
|
||||
*/
|
||||
async archiveCheckbox(checkboxId: string): Promise<DailyCheckbox> {
|
||||
const result = await httpClient.patch<ApiCheckbox>(`/daily/checkboxes/${checkboxId}/archive`);
|
||||
const result = await httpClient.patch<ApiCheckbox>(
|
||||
`/daily/checkboxes/${checkboxId}/archive`
|
||||
);
|
||||
return this.transformCheckboxDates(result);
|
||||
}
|
||||
}
|
||||
|
||||
// Instance singleton du client
|
||||
export const dailyClient = new DailyClient();
|
||||
export const dailyClient = new DailyClient();
|
||||
|
||||
@@ -46,7 +46,7 @@ export class JiraClient extends HttpClient {
|
||||
async toggleScheduler(enabled: boolean): Promise<JiraSchedulerStatus> {
|
||||
const response = await this.post<{ data: JiraSchedulerStatus }>('/sync', {
|
||||
action: 'scheduler',
|
||||
enabled
|
||||
enabled,
|
||||
});
|
||||
return response.data;
|
||||
}
|
||||
@@ -54,11 +54,14 @@ export class JiraClient extends HttpClient {
|
||||
/**
|
||||
* Met à jour la configuration du scheduler
|
||||
*/
|
||||
async updateSchedulerConfig(jiraAutoSync: boolean, jiraSyncInterval: 'hourly' | 'daily' | 'weekly'): Promise<JiraSchedulerStatus> {
|
||||
async updateSchedulerConfig(
|
||||
jiraAutoSync: boolean,
|
||||
jiraSyncInterval: 'hourly' | 'daily' | 'weekly'
|
||||
): Promise<JiraSchedulerStatus> {
|
||||
const response = await this.post<{ data: JiraSchedulerStatus }>('/sync', {
|
||||
action: 'config',
|
||||
jiraAutoSync,
|
||||
jiraSyncInterval
|
||||
jiraSyncInterval,
|
||||
});
|
||||
return response.data;
|
||||
}
|
||||
|
||||
@@ -33,7 +33,9 @@ class JiraConfigClient {
|
||||
/**
|
||||
* Sauvegarde la configuration Jira
|
||||
*/
|
||||
async saveJiraConfig(config: SaveJiraConfigRequest): Promise<SaveJiraConfigResponse> {
|
||||
async saveJiraConfig(
|
||||
config: SaveJiraConfigRequest
|
||||
): Promise<SaveJiraConfigResponse> {
|
||||
return httpClient.put<SaveJiraConfigResponse>(this.basePath, config);
|
||||
}
|
||||
|
||||
|
||||
@@ -43,27 +43,33 @@ export class TagsClient extends HttpClient {
|
||||
*/
|
||||
async getTags(filters?: TagFilters): Promise<TagsResponse> {
|
||||
const params: Record<string, string> = {};
|
||||
|
||||
|
||||
if (filters?.q) {
|
||||
params.q = filters.q;
|
||||
}
|
||||
|
||||
|
||||
if (filters?.popular) {
|
||||
params.popular = 'true';
|
||||
}
|
||||
|
||||
|
||||
if (filters?.limit) {
|
||||
params.limit = filters.limit.toString();
|
||||
}
|
||||
|
||||
return this.get<TagsResponse>('', Object.keys(params).length > 0 ? params : undefined);
|
||||
return this.get<TagsResponse>(
|
||||
'',
|
||||
Object.keys(params).length > 0 ? params : undefined
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Récupère les tags populaires (les plus utilisés)
|
||||
*/
|
||||
async getPopularTags(limit: number = 10): Promise<PopularTagsResponse> {
|
||||
return this.get<PopularTagsResponse>('', { popular: 'true', limit: limit.toString() });
|
||||
return this.get<PopularTagsResponse>('', {
|
||||
popular: 'true',
|
||||
limit: limit.toString(),
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -121,4 +127,4 @@ export class TagsClient extends HttpClient {
|
||||
}
|
||||
|
||||
// Instance singleton
|
||||
export const tagsClient = new TagsClient();
|
||||
export const tagsClient = new TagsClient();
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
import { httpClient } from './base/http-client';
|
||||
import { Task, TaskStatus, TaskPriority, TaskStats, DailyCheckbox } from '@/lib/types';
|
||||
import {
|
||||
Task,
|
||||
TaskStatus,
|
||||
TaskPriority,
|
||||
TaskStats,
|
||||
DailyCheckbox,
|
||||
} from '@/lib/types';
|
||||
|
||||
export interface TaskFilters {
|
||||
status?: TaskStatus[];
|
||||
@@ -39,13 +45,12 @@ export interface UpdateTaskData {
|
||||
* Client pour la gestion des tâches
|
||||
*/
|
||||
export class TasksClient {
|
||||
|
||||
/**
|
||||
* Récupère toutes les tâches avec filtres
|
||||
*/
|
||||
async getTasks(filters?: TaskFilters): Promise<TasksResponse> {
|
||||
const params: Record<string, string> = {};
|
||||
|
||||
|
||||
if (filters?.status) {
|
||||
params.status = filters.status.join(',');
|
||||
}
|
||||
@@ -69,7 +74,9 @@ export class TasksClient {
|
||||
* Récupère les daily checkboxes liées à une tâche
|
||||
*/
|
||||
async getTaskCheckboxes(taskId: string): Promise<DailyCheckbox[]> {
|
||||
const response = await httpClient.get<{ data: DailyCheckbox[] }>(`/tasks/${taskId}/checkboxes`);
|
||||
const response = await httpClient.get<{ data: DailyCheckbox[] }>(
|
||||
`/tasks/${taskId}/checkboxes`
|
||||
);
|
||||
return response.data;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user