feat(DailyCheckboxItem, TaskCard, DailyService): enhance task emoji handling and improve data fetching
- Added emoji support in DailyCheckboxItem and TaskCard components using getTaskEmoji. - Updated DailyService to include taskTags and primaryTag in checkbox data fetching, improving task detail retrieval. - Refactored mapPrismaCheckbox to handle taskTags and primaryTag extraction for better task representation.
This commit is contained in:
@@ -61,7 +61,19 @@ export class DailyService {
|
||||
date: normalizedDate,
|
||||
userId: userId,
|
||||
},
|
||||
include: { task: true, user: true },
|
||||
include: {
|
||||
task: {
|
||||
include: {
|
||||
taskTags: {
|
||||
include: {
|
||||
tag: true,
|
||||
},
|
||||
},
|
||||
primaryTag: true,
|
||||
},
|
||||
},
|
||||
user: true,
|
||||
},
|
||||
orderBy: { order: 'asc' },
|
||||
});
|
||||
|
||||
@@ -93,7 +105,19 @@ export class DailyService {
|
||||
order,
|
||||
isChecked: data.isChecked ?? false,
|
||||
},
|
||||
include: { task: true, user: true },
|
||||
include: {
|
||||
task: {
|
||||
include: {
|
||||
taskTags: {
|
||||
include: {
|
||||
tag: true,
|
||||
},
|
||||
},
|
||||
primaryTag: true,
|
||||
},
|
||||
},
|
||||
user: true,
|
||||
},
|
||||
});
|
||||
|
||||
return this.mapPrismaCheckbox(checkbox);
|
||||
@@ -124,7 +148,19 @@ export class DailyService {
|
||||
const checkbox = await prisma.dailyCheckbox.update({
|
||||
where: { id: checkboxId },
|
||||
data: updateData,
|
||||
include: { task: true, user: true },
|
||||
include: {
|
||||
task: {
|
||||
include: {
|
||||
taskTags: {
|
||||
include: {
|
||||
tag: true,
|
||||
},
|
||||
},
|
||||
primaryTag: true,
|
||||
},
|
||||
},
|
||||
user: true,
|
||||
},
|
||||
});
|
||||
|
||||
return this.mapPrismaCheckbox(checkbox);
|
||||
@@ -145,7 +181,19 @@ export class DailyService {
|
||||
const updated = await prisma.dailyCheckbox.update({
|
||||
where: { id: checkboxId },
|
||||
data: { isChecked: !existing.isChecked, updatedAt: new Date() },
|
||||
include: { task: true, user: true },
|
||||
include: {
|
||||
task: {
|
||||
include: {
|
||||
taskTags: {
|
||||
include: {
|
||||
tag: true,
|
||||
},
|
||||
},
|
||||
primaryTag: true,
|
||||
},
|
||||
},
|
||||
user: true,
|
||||
},
|
||||
});
|
||||
|
||||
return this.mapPrismaCheckbox(updated);
|
||||
@@ -195,7 +243,19 @@ export class DailyService {
|
||||
contains: query,
|
||||
},
|
||||
},
|
||||
include: { task: true, user: true },
|
||||
include: {
|
||||
task: {
|
||||
include: {
|
||||
taskTags: {
|
||||
include: {
|
||||
tag: true,
|
||||
},
|
||||
},
|
||||
primaryTag: true,
|
||||
},
|
||||
},
|
||||
user: true,
|
||||
},
|
||||
orderBy: { date: 'desc' },
|
||||
take: limit,
|
||||
});
|
||||
@@ -271,12 +331,76 @@ export class DailyService {
|
||||
|
||||
/**
|
||||
* Mappe une checkbox Prisma vers notre interface
|
||||
* Accepte les checkboxes avec ou sans les relations taskTags et primaryTag
|
||||
*/
|
||||
private mapPrismaCheckbox(
|
||||
checkbox: Prisma.DailyCheckboxGetPayload<{
|
||||
include: { task: true; user: true };
|
||||
include: {
|
||||
task:
|
||||
| true
|
||||
| {
|
||||
include: {
|
||||
taskTags: {
|
||||
include: {
|
||||
tag: true;
|
||||
};
|
||||
};
|
||||
primaryTag: true;
|
||||
};
|
||||
};
|
||||
user: true;
|
||||
};
|
||||
}>
|
||||
): DailyCheckbox {
|
||||
// Extraire les tags de la tâche si elle existe
|
||||
let taskTags: string[] = [];
|
||||
let taskTagDetails:
|
||||
| Array<{ id: string; name: string; color: string; isPinned?: boolean }>
|
||||
| undefined = undefined;
|
||||
let taskPrimaryTag:
|
||||
| { id: string; name: string; color: string; isPinned?: boolean }
|
||||
| undefined = undefined;
|
||||
|
||||
if (checkbox.task) {
|
||||
// Vérifier si taskTags est disponible (peut être true ou un objet avec include)
|
||||
const taskWithTags = checkbox.task as unknown as {
|
||||
taskTags?: Array<{
|
||||
tag: { id: string; name: string; color: string; isPinned: boolean };
|
||||
}>;
|
||||
primaryTag?: {
|
||||
id: string;
|
||||
name: string;
|
||||
color: string;
|
||||
isPinned: boolean;
|
||||
} | null;
|
||||
};
|
||||
|
||||
if (
|
||||
'taskTags' in taskWithTags &&
|
||||
taskWithTags.taskTags &&
|
||||
Array.isArray(taskWithTags.taskTags)
|
||||
) {
|
||||
// Utiliser les relations Prisma pour récupérer les noms et détails des tags
|
||||
taskTags = taskWithTags.taskTags.map((tt) => tt.tag.name);
|
||||
taskTagDetails = taskWithTags.taskTags.map((tt) => ({
|
||||
id: tt.tag.id,
|
||||
name: tt.tag.name,
|
||||
color: tt.tag.color,
|
||||
isPinned: tt.tag.isPinned,
|
||||
}));
|
||||
}
|
||||
|
||||
// Extraire le primaryTag si disponible
|
||||
if ('primaryTag' in taskWithTags && taskWithTags.primaryTag) {
|
||||
taskPrimaryTag = {
|
||||
id: taskWithTags.primaryTag.id,
|
||||
name: taskWithTags.primaryTag.name,
|
||||
color: taskWithTags.primaryTag.color,
|
||||
isPinned: taskWithTags.primaryTag.isPinned,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
id: checkbox.id,
|
||||
date: checkbox.date,
|
||||
@@ -295,7 +419,10 @@ export class DailyService {
|
||||
priority: checkbox.task.priority as TaskPriority,
|
||||
source: checkbox.task.source as TaskSource,
|
||||
sourceId: checkbox.task.sourceId || undefined,
|
||||
tags: [], // Les tags seront chargés séparément si nécessaire
|
||||
tags: taskTags,
|
||||
tagDetails: taskTagDetails,
|
||||
primaryTagId: checkbox.task.primaryTagId || undefined,
|
||||
primaryTag: taskPrimaryTag,
|
||||
dueDate: checkbox.task.dueDate || undefined,
|
||||
completedAt: checkbox.task.completedAt || undefined,
|
||||
createdAt: checkbox.task.createdAt,
|
||||
@@ -384,7 +511,19 @@ export class DailyService {
|
||||
|
||||
const checkboxes = await prisma.dailyCheckbox.findMany({
|
||||
where: whereConditions,
|
||||
include: { task: true, user: true },
|
||||
include: {
|
||||
task: {
|
||||
include: {
|
||||
taskTags: {
|
||||
include: {
|
||||
tag: true,
|
||||
},
|
||||
},
|
||||
primaryTag: true,
|
||||
},
|
||||
},
|
||||
user: true,
|
||||
},
|
||||
orderBy: [{ date: 'desc' }, { order: 'asc' }],
|
||||
...(options?.limit ? { take: options.limit } : {}),
|
||||
});
|
||||
@@ -406,7 +545,19 @@ export class DailyService {
|
||||
?.text + ' [ARCHIVÉ]',
|
||||
updatedAt: new Date(),
|
||||
},
|
||||
include: { task: true, user: true },
|
||||
include: {
|
||||
task: {
|
||||
include: {
|
||||
taskTags: {
|
||||
include: {
|
||||
tag: true,
|
||||
},
|
||||
},
|
||||
primaryTag: true,
|
||||
},
|
||||
},
|
||||
user: true,
|
||||
},
|
||||
});
|
||||
|
||||
return this.mapPrismaCheckbox(checkbox);
|
||||
@@ -450,7 +601,19 @@ export class DailyService {
|
||||
order: newOrder,
|
||||
updatedAt: new Date(),
|
||||
},
|
||||
include: { task: true, user: true },
|
||||
include: {
|
||||
task: {
|
||||
include: {
|
||||
taskTags: {
|
||||
include: {
|
||||
tag: true,
|
||||
},
|
||||
},
|
||||
primaryTag: true,
|
||||
},
|
||||
},
|
||||
user: true,
|
||||
},
|
||||
});
|
||||
|
||||
return this.mapPrismaCheckbox(updatedCheckbox);
|
||||
|
||||
Reference in New Issue
Block a user