feat: add "Move to Today" functionality for pending tasks
- Implemented a new button in the `PendingTasksSection` to move unchecked tasks to today's date. - Created `moveCheckboxToToday` action in `daily.ts` to handle the logic for moving tasks. - Updated `DailyPageClient` and `PendingTasksSection` to integrate the new functionality and refresh the daily view after moving tasks. - Marked the feature as completed in `TODO.md`.
This commit is contained in:
@@ -94,6 +94,7 @@ export class DailyService {
|
||||
}
|
||||
}
|
||||
if (data.order !== undefined) updateData.order = data.order;
|
||||
if (data.date !== undefined) updateData.date = normalizeDate(data.date);
|
||||
|
||||
const checkbox = await prisma.dailyCheckbox.update({
|
||||
where: { id: checkboxId },
|
||||
@@ -327,6 +328,50 @@ export class DailyService {
|
||||
|
||||
return this.mapPrismaCheckbox(checkbox);
|
||||
}
|
||||
|
||||
/**
|
||||
* Déplace une checkbox non cochée à aujourd'hui
|
||||
*/
|
||||
async moveCheckboxToToday(checkboxId: string): Promise<DailyCheckbox> {
|
||||
const checkbox = await prisma.dailyCheckbox.findUnique({
|
||||
where: { id: checkboxId }
|
||||
});
|
||||
|
||||
if (!checkbox) {
|
||||
throw new BusinessError('Checkbox non trouvée');
|
||||
}
|
||||
|
||||
if (checkbox.isChecked) {
|
||||
throw new BusinessError('Impossible de déplacer une tâche déjà cochée');
|
||||
}
|
||||
|
||||
const today = normalizeDate(getToday());
|
||||
|
||||
// Vérifier si la checkbox est déjà pour aujourd'hui
|
||||
if (normalizeDate(checkbox.date).getTime() === today.getTime()) {
|
||||
throw new BusinessError('La tâche est déjà programmée pour aujourd\'hui');
|
||||
}
|
||||
|
||||
// Calculer l'ordre suivant pour aujourd'hui
|
||||
const maxOrder = await prisma.dailyCheckbox.aggregate({
|
||||
where: { date: today },
|
||||
_max: { order: true }
|
||||
});
|
||||
|
||||
const newOrder = (maxOrder._max.order ?? -1) + 1;
|
||||
|
||||
const updatedCheckbox = await prisma.dailyCheckbox.update({
|
||||
where: { id: checkboxId },
|
||||
data: {
|
||||
date: today,
|
||||
order: newOrder,
|
||||
updatedAt: new Date()
|
||||
},
|
||||
include: { task: true }
|
||||
});
|
||||
|
||||
return this.mapPrismaCheckbox(updatedCheckbox);
|
||||
}
|
||||
}
|
||||
|
||||
// Instance singleton du service
|
||||
|
||||
Reference in New Issue
Block a user