- Marked tasks as completed in TODO for Daily management service, data model, and interactive checkboxes. - Added a new link to the Daily page in the Header component for easy navigation. - Introduced DailyCheckbox model in Prisma schema and corresponding TypeScript interfaces for better data handling. - Updated database schema to include daily checkboxes, enhancing task management capabilities.
153 lines
3.8 KiB
TypeScript
153 lines
3.8 KiB
TypeScript
import { httpClient } from './base/http-client';
|
|
import { DailyCheckbox, DailyView, CreateDailyCheckboxData, UpdateDailyCheckboxData } from '@/lib/types';
|
|
|
|
export interface DailyHistoryFilters {
|
|
limit?: number;
|
|
}
|
|
|
|
export interface DailySearchFilters {
|
|
query: string;
|
|
limit?: number;
|
|
}
|
|
|
|
export interface ReorderCheckboxesData {
|
|
date: Date;
|
|
checkboxIds: string[];
|
|
}
|
|
|
|
export class DailyClient {
|
|
/**
|
|
* Récupère la vue daily d'aujourd'hui (hier + aujourd'hui)
|
|
*/
|
|
async getTodaysDailyView(): Promise<DailyView> {
|
|
return httpClient.get('/daily');
|
|
}
|
|
|
|
/**
|
|
* Récupère la vue daily pour une date donnée
|
|
*/
|
|
async getDailyView(date: Date): Promise<DailyView> {
|
|
const dateStr = this.formatDateForAPI(date);
|
|
return httpClient.get(`/daily?date=${dateStr}`);
|
|
}
|
|
|
|
/**
|
|
* Récupère l'historique des checkboxes
|
|
*/
|
|
async getCheckboxHistory(filters?: DailyHistoryFilters): Promise<{ date: Date; checkboxes: DailyCheckbox[] }[]> {
|
|
const params = new URLSearchParams({ action: 'history' });
|
|
|
|
if (filters?.limit) params.append('limit', filters.limit.toString());
|
|
|
|
return httpClient.get(`/daily?${params}`);
|
|
}
|
|
|
|
/**
|
|
* Recherche dans les checkboxes
|
|
*/
|
|
async searchCheckboxes(filters: DailySearchFilters): Promise<DailyCheckbox[]> {
|
|
const params = new URLSearchParams({
|
|
action: 'search',
|
|
q: filters.query
|
|
});
|
|
|
|
if (filters.limit) params.append('limit', filters.limit.toString());
|
|
|
|
return httpClient.get(`/daily?${params}`);
|
|
}
|
|
|
|
/**
|
|
* Ajoute une checkbox
|
|
*/
|
|
async addCheckbox(data: CreateDailyCheckboxData): Promise<DailyCheckbox> {
|
|
return httpClient.post('/daily', {
|
|
...data,
|
|
date: this.formatDateForAPI(data.date)
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Ajoute une checkbox pour aujourd'hui
|
|
*/
|
|
async addTodayCheckbox(text: string, taskId?: string): Promise<DailyCheckbox> {
|
|
return this.addCheckbox({
|
|
date: new Date(),
|
|
text,
|
|
taskId
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Ajoute une checkbox pour hier
|
|
*/
|
|
async addYesterdayCheckbox(text: string, taskId?: string): Promise<DailyCheckbox> {
|
|
const yesterday = new Date();
|
|
yesterday.setDate(yesterday.getDate() - 1);
|
|
|
|
return this.addCheckbox({
|
|
date: yesterday,
|
|
text,
|
|
taskId
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Met à jour une checkbox
|
|
*/
|
|
async updateCheckbox(checkboxId: string, data: UpdateDailyCheckboxData): Promise<DailyCheckbox> {
|
|
return httpClient.patch(`/daily/checkboxes/${checkboxId}`, data);
|
|
}
|
|
|
|
/**
|
|
* Supprime une checkbox
|
|
*/
|
|
async deleteCheckbox(checkboxId: string): Promise<void> {
|
|
return httpClient.delete(`/daily/checkboxes/${checkboxId}`);
|
|
}
|
|
|
|
/**
|
|
* Réordonne les checkboxes d'une date
|
|
*/
|
|
async reorderCheckboxes(data: ReorderCheckboxesData): Promise<void> {
|
|
return httpClient.post('/daily/checkboxes', {
|
|
date: this.formatDateForAPI(data.date),
|
|
checkboxIds: data.checkboxIds
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Coche/décoche une checkbox (raccourci)
|
|
*/
|
|
async toggleCheckbox(checkboxId: string, isChecked: boolean): Promise<DailyCheckbox> {
|
|
return this.updateCheckbox(checkboxId, { isChecked });
|
|
}
|
|
|
|
/**
|
|
* Formate une date pour l'API
|
|
*/
|
|
formatDateForAPI(date: Date): string {
|
|
return date.toISOString().split('T')[0]; // YYYY-MM-DD
|
|
}
|
|
|
|
/**
|
|
* Récupère la vue daily d'une date relative (hier, aujourd'hui, demain)
|
|
*/
|
|
async getDailyViewByRelativeDate(relative: 'yesterday' | 'today' | 'tomorrow'): Promise<DailyView> {
|
|
const date = new Date();
|
|
|
|
switch (relative) {
|
|
case 'yesterday':
|
|
date.setDate(date.getDate() - 1);
|
|
break;
|
|
case 'tomorrow':
|
|
date.setDate(date.getDate() + 1);
|
|
break;
|
|
// 'today' ne change rien
|
|
}
|
|
|
|
return this.getDailyView(date);
|
|
}
|
|
}
|
|
|
|
// Instance singleton du client
|
|
export const dailyClient = new DailyClient(); |