feat: refactor daily task management with new pending tasks section

- Added `PendingTasksSection` to `DailyPageClient` for displaying uncompleted tasks.
- Implemented `getPendingCheckboxes` method in `DailyClient` and `DailyService` to fetch pending tasks.
- Introduced `getDaysAgo` utility function for calculating elapsed days since a date.
- Updated `TODO.md` to reflect the new task management features and adjustments.
- Cleaned up and organized folder structure to align with Next.js 13+ best practices.
This commit is contained in:
Julien Froidefond
2025-09-21 19:55:04 +02:00
parent 0a03e40469
commit 3cfed60f43
9 changed files with 482 additions and 64 deletions

View File

@@ -257,6 +257,76 @@ export class DailyService {
return formatDateForAPI(checkbox.date);
});
}
/**
* Récupère toutes les checkboxes non cochées (tâches en attente)
*/
async getPendingCheckboxes(options?: {
maxDays?: number;
excludeToday?: boolean;
type?: DailyCheckboxType;
limit?: number;
}): Promise<DailyCheckbox[]> {
const today = normalizeDate(getToday());
const maxDays = options?.maxDays ?? 30;
const excludeToday = options?.excludeToday ?? true;
// Calculer la date limite (maxDays jours en arrière)
const limitDate = new Date(today);
limitDate.setDate(limitDate.getDate() - maxDays);
// Construire les conditions de filtrage
const whereConditions: {
isChecked: boolean;
date: {
gte: Date;
lt?: Date;
lte?: Date;
};
type?: DailyCheckboxType;
} = {
isChecked: false,
date: {
gte: limitDate,
...(excludeToday ? { lt: today } : { lte: today })
}
};
// Filtrer par type si spécifié
if (options?.type) {
whereConditions.type = options.type;
}
const checkboxes = await prisma.dailyCheckbox.findMany({
where: whereConditions,
include: { task: true },
orderBy: [
{ date: 'desc' },
{ order: 'asc' }
],
...(options?.limit ? { take: options.limit } : {})
});
return checkboxes.map(this.mapPrismaCheckbox);
}
/**
* Archive une checkbox (marque comme archivée sans la cocher)
*/
async archiveCheckbox(checkboxId: string): Promise<DailyCheckbox> {
// Pour l'instant, on utilise un champ text pour marquer comme archivé
// Plus tard on pourra ajouter un champ dédié dans la DB
const checkbox = await prisma.dailyCheckbox.update({
where: { id: checkboxId },
data: {
text: (await prisma.dailyCheckbox.findUnique({ where: { id: checkboxId } }))?.text + ' [ARCHIVÉ]',
updatedAt: new Date()
},
include: { task: true }
});
return this.mapPrismaCheckbox(checkbox);
}
}
// Instance singleton du service