feat(DailyService): implement toggleCheckbox method for direct checkbox state updates
This commit is contained in:
@@ -30,28 +30,8 @@ export async function toggleCheckbox(checkboxId: string): Promise<{
|
||||
return { success: false, error: 'Non authentifié' };
|
||||
}
|
||||
|
||||
// Nous devons d'abord récupérer la checkbox pour connaître son état actuel
|
||||
// En absence de getCheckboxById, nous allons essayer de la trouver via une vue daily
|
||||
// Pour l'instant, nous allons simplement toggle via updateCheckbox
|
||||
// (le front-end gère déjà l'état optimiste)
|
||||
|
||||
// Récupérer toutes les checkboxes d'aujourd'hui et hier pour trouver celle à toggle
|
||||
const today = getToday();
|
||||
const dailyView = await dailyService.getDailyView(today, session.user.id);
|
||||
|
||||
let checkbox = dailyView.today.find((cb) => cb.id === checkboxId);
|
||||
if (!checkbox) {
|
||||
checkbox = dailyView.yesterday.find((cb) => cb.id === checkboxId);
|
||||
}
|
||||
|
||||
if (!checkbox) {
|
||||
return { success: false, error: 'Checkbox non trouvée' };
|
||||
}
|
||||
|
||||
// Toggle l'état
|
||||
const updatedCheckbox = await dailyService.updateCheckbox(checkboxId, {
|
||||
isChecked: !checkbox.isChecked,
|
||||
});
|
||||
// Toggle direct côté service par ID (indépendant de la date)
|
||||
const updatedCheckbox = await dailyService.toggleCheckbox(checkboxId);
|
||||
|
||||
revalidatePath('/daily');
|
||||
return { success: true, data: updatedCheckbox };
|
||||
@@ -70,7 +50,8 @@ export async function toggleCheckbox(checkboxId: string): Promise<{
|
||||
export async function addTodayCheckbox(
|
||||
content: string,
|
||||
type?: 'task' | 'meeting',
|
||||
taskId?: string
|
||||
taskId?: string,
|
||||
date?: Date
|
||||
): Promise<{
|
||||
success: boolean;
|
||||
data?: DailyCheckbox;
|
||||
@@ -82,8 +63,10 @@ export async function addTodayCheckbox(
|
||||
return { success: false, error: 'Non authentifié' };
|
||||
}
|
||||
|
||||
const targetDate = normalizeDate(date || getToday());
|
||||
|
||||
const newCheckbox = await dailyService.addCheckbox({
|
||||
date: getToday(),
|
||||
date: targetDate,
|
||||
userId: session.user.id,
|
||||
text: content,
|
||||
type: type || 'task',
|
||||
@@ -107,7 +90,8 @@ export async function addTodayCheckbox(
|
||||
export async function addYesterdayCheckbox(
|
||||
content: string,
|
||||
type?: 'task' | 'meeting',
|
||||
taskId?: string
|
||||
taskId?: string,
|
||||
baseDate?: Date
|
||||
): Promise<{
|
||||
success: boolean;
|
||||
data?: DailyCheckbox;
|
||||
@@ -119,7 +103,8 @@ export async function addYesterdayCheckbox(
|
||||
return { success: false, error: 'Non authentifié' };
|
||||
}
|
||||
|
||||
const yesterday = getPreviousWorkday(getToday());
|
||||
const base = normalizeDate(baseDate || getToday());
|
||||
const yesterday = getPreviousWorkday(base);
|
||||
|
||||
const newCheckbox = await dailyService.addCheckbox({
|
||||
date: yesterday,
|
||||
|
||||
@@ -120,7 +120,12 @@ export function useDaily(
|
||||
try {
|
||||
setError(null);
|
||||
|
||||
const result = await addTodayCheckboxAction(text, type, taskId);
|
||||
const result = await addTodayCheckboxAction(
|
||||
text,
|
||||
type,
|
||||
taskId,
|
||||
currentDate
|
||||
);
|
||||
|
||||
if (result.success && result.data) {
|
||||
// Mise à jour optimiste
|
||||
@@ -167,7 +172,12 @@ export function useDaily(
|
||||
try {
|
||||
setError(null);
|
||||
|
||||
const result = await addYesterdayCheckboxAction(text, type, taskId);
|
||||
const result = await addYesterdayCheckboxAction(
|
||||
text,
|
||||
type,
|
||||
taskId,
|
||||
currentDate
|
||||
);
|
||||
|
||||
if (result.success && result.data) {
|
||||
// Mise à jour optimiste
|
||||
|
||||
@@ -130,6 +130,27 @@ export class DailyService {
|
||||
return this.mapPrismaCheckbox(checkbox);
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggle l'état d'une checkbox par son ID (indépendant de la date)
|
||||
*/
|
||||
async toggleCheckbox(checkboxId: string): Promise<DailyCheckbox> {
|
||||
const existing = await prisma.dailyCheckbox.findUnique({
|
||||
where: { id: checkboxId },
|
||||
});
|
||||
|
||||
if (!existing) {
|
||||
throw new BusinessError('Checkbox non trouvée');
|
||||
}
|
||||
|
||||
const updated = await prisma.dailyCheckbox.update({
|
||||
where: { id: checkboxId },
|
||||
data: { isChecked: !existing.isChecked, updatedAt: new Date() },
|
||||
include: { task: true, user: true },
|
||||
});
|
||||
|
||||
return this.mapPrismaCheckbox(updated);
|
||||
}
|
||||
|
||||
/**
|
||||
* Supprime une checkbox
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user