feat(Task): implement user ownership for tasks and enhance related services
- Added ownerId field to Task model to associate tasks with users. - Updated TaskService methods to enforce user ownership in task operations. - Enhanced API routes to include user authentication and ownership checks. - Modified DailyService and analytics services to filter tasks by user. - Integrated user session handling in various components for personalized task management.
This commit is contained in:
@@ -282,6 +282,7 @@ export class DailyService {
|
||||
jiraProject: checkbox.task.jiraProject || undefined,
|
||||
jiraKey: checkbox.task.jiraKey || undefined,
|
||||
assignee: checkbox.task.assignee || undefined,
|
||||
ownerId: (checkbox.task as unknown as { ownerId: string }).ownerId, // Cast temporaire jusqu'à ce que Prisma soit mis à jour
|
||||
}
|
||||
: undefined,
|
||||
isArchived: checkbox.text.includes('[ARCHIVÉ]'),
|
||||
@@ -293,8 +294,16 @@ export class DailyService {
|
||||
/**
|
||||
* Récupère toutes les dates qui ont des checkboxes (pour le calendrier)
|
||||
*/
|
||||
async getDailyDates(): Promise<string[]> {
|
||||
async getDailyDates(userId?: string): Promise<string[]> {
|
||||
const whereConditions: Prisma.DailyCheckboxWhereInput = {};
|
||||
|
||||
// Filtrer par utilisateur si spécifié
|
||||
if (userId) {
|
||||
whereConditions.userId = userId;
|
||||
}
|
||||
|
||||
const checkboxes = await prisma.dailyCheckbox.findMany({
|
||||
where: whereConditions,
|
||||
select: {
|
||||
date: true,
|
||||
},
|
||||
@@ -317,6 +326,7 @@ export class DailyService {
|
||||
excludeToday?: boolean;
|
||||
type?: DailyCheckboxType;
|
||||
limit?: number;
|
||||
userId?: string; // Filtrer par utilisateur
|
||||
}): Promise<DailyCheckbox[]> {
|
||||
const today = normalizeDate(getToday());
|
||||
const maxDays = options?.maxDays ?? 30;
|
||||
@@ -327,15 +337,7 @@ export class DailyService {
|
||||
limitDate.setDate(limitDate.getDate() - maxDays);
|
||||
|
||||
// Construire les conditions de filtrage
|
||||
const whereConditions: {
|
||||
isChecked: boolean;
|
||||
date: {
|
||||
gte: Date;
|
||||
lt?: Date;
|
||||
lte?: Date;
|
||||
};
|
||||
type?: DailyCheckboxType;
|
||||
} = {
|
||||
const whereConditions: Prisma.DailyCheckboxWhereInput = {
|
||||
isChecked: false,
|
||||
date: {
|
||||
gte: limitDate,
|
||||
@@ -348,6 +350,17 @@ export class DailyService {
|
||||
whereConditions.type = options.type;
|
||||
}
|
||||
|
||||
// Filtrer par utilisateur si spécifié
|
||||
if (options?.userId) {
|
||||
whereConditions.userId = options.userId;
|
||||
|
||||
// S'assurer que si le todo est lié à une tâche, cette tâche appartient bien à l'utilisateur
|
||||
whereConditions.OR = [
|
||||
{ task: null }, // Todos standalone (sans tâche associée)
|
||||
{ task: { ownerId: options.userId } }, // Todos liés à une tâche de l'utilisateur
|
||||
];
|
||||
}
|
||||
|
||||
const checkboxes = await prisma.dailyCheckbox.findMany({
|
||||
where: whereConditions,
|
||||
include: { task: true, user: true },
|
||||
|
||||
Reference in New Issue
Block a user