feat(DailyCheckbox): associate checkboxes with users and enhance daily view functionality
- Added userId field to DailyCheckbox model for user association. - Updated DailyService methods to handle user-specific checkbox retrieval and management. - Integrated user authentication checks in API routes and actions for secure access to daily data. - Enhanced DailyPage to display user-specific daily views, ensuring proper session handling. - Updated client and service interfaces to reflect changes in data structure.
This commit is contained in:
@@ -26,7 +26,7 @@ export class DailyService {
|
||||
/**
|
||||
* Récupère la vue daily pour une date donnée (checkboxes d'hier et d'aujourd'hui)
|
||||
*/
|
||||
async getDailyView(date: Date): Promise<DailyView> {
|
||||
async getDailyView(date: Date, userId: string): Promise<DailyView> {
|
||||
// Normaliser la date (début de journée)
|
||||
const today = normalizeDate(date);
|
||||
|
||||
@@ -35,8 +35,8 @@ export class DailyService {
|
||||
|
||||
// Récupérer les checkboxes des deux jours
|
||||
const [yesterdayCheckboxes, todayCheckboxes] = await Promise.all([
|
||||
this.getCheckboxesByDate(yesterday),
|
||||
this.getCheckboxesByDate(today),
|
||||
this.getCheckboxesByDate(yesterday, userId),
|
||||
this.getCheckboxesByDate(today, userId),
|
||||
]);
|
||||
|
||||
return {
|
||||
@@ -47,15 +47,21 @@ export class DailyService {
|
||||
}
|
||||
|
||||
/**
|
||||
* Récupère toutes les checkboxes d'une date donnée
|
||||
* Récupère toutes les checkboxes d'une date donnée pour un utilisateur
|
||||
*/
|
||||
async getCheckboxesByDate(date: Date): Promise<DailyCheckbox[]> {
|
||||
async getCheckboxesByDate(
|
||||
date: Date,
|
||||
userId: string
|
||||
): Promise<DailyCheckbox[]> {
|
||||
// Normaliser la date (début de journée)
|
||||
const normalizedDate = normalizeDate(date);
|
||||
|
||||
const checkboxes = await prisma.dailyCheckbox.findMany({
|
||||
where: { date: normalizedDate },
|
||||
include: { task: true },
|
||||
where: {
|
||||
date: normalizedDate,
|
||||
userId: userId,
|
||||
},
|
||||
include: { task: true, user: true },
|
||||
orderBy: { order: 'asc' },
|
||||
});
|
||||
|
||||
@@ -83,10 +89,11 @@ export class DailyService {
|
||||
text: data.text.trim(),
|
||||
type: data.type ?? 'task',
|
||||
taskId: data.taskId,
|
||||
userId: data.userId,
|
||||
order,
|
||||
isChecked: data.isChecked ?? false,
|
||||
},
|
||||
include: { task: true },
|
||||
include: { task: true, user: true },
|
||||
});
|
||||
|
||||
return this.mapPrismaCheckbox(checkbox);
|
||||
@@ -117,7 +124,7 @@ export class DailyService {
|
||||
const checkbox = await prisma.dailyCheckbox.update({
|
||||
where: { id: checkboxId },
|
||||
data: updateData,
|
||||
include: { task: true },
|
||||
include: { task: true, user: true },
|
||||
});
|
||||
|
||||
return this.mapPrismaCheckbox(checkbox);
|
||||
@@ -167,7 +174,7 @@ export class DailyService {
|
||||
contains: query,
|
||||
},
|
||||
},
|
||||
include: { task: true },
|
||||
include: { task: true, user: true },
|
||||
orderBy: { date: 'desc' },
|
||||
take: limit,
|
||||
});
|
||||
@@ -179,10 +186,12 @@ export class DailyService {
|
||||
* Récupère l'historique des checkboxes (groupées par date)
|
||||
*/
|
||||
async getCheckboxHistory(
|
||||
userId: string,
|
||||
limit: number = 30
|
||||
): Promise<{ date: Date; checkboxes: DailyCheckbox[] }[]> {
|
||||
// Récupérer les dates distinctes des dernières checkboxes
|
||||
// Récupérer les dates distinctes des dernières checkboxes pour cet utilisateur
|
||||
const distinctDates = await prisma.dailyCheckbox.findMany({
|
||||
where: { userId },
|
||||
select: { date: true },
|
||||
distinct: ['date'],
|
||||
orderBy: { date: 'desc' },
|
||||
@@ -191,7 +200,7 @@ export class DailyService {
|
||||
|
||||
const history = [];
|
||||
for (const { date } of distinctDates) {
|
||||
const checkboxes = await this.getCheckboxesByDate(date);
|
||||
const checkboxes = await this.getCheckboxesByDate(date, userId);
|
||||
if (checkboxes.length > 0) {
|
||||
history.push({ date, checkboxes });
|
||||
}
|
||||
@@ -203,19 +212,21 @@ export class DailyService {
|
||||
/**
|
||||
* Récupère la vue daily d'aujourd'hui
|
||||
*/
|
||||
async getTodaysDailyView(): Promise<DailyView> {
|
||||
return this.getDailyView(getToday());
|
||||
async getTodaysDailyView(userId: string): Promise<DailyView> {
|
||||
return this.getDailyView(getToday(), userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ajoute une checkbox pour aujourd'hui
|
||||
*/
|
||||
async addTodayCheckbox(
|
||||
userId: string,
|
||||
text: string,
|
||||
taskId?: string
|
||||
): Promise<DailyCheckbox> {
|
||||
return this.addCheckbox({
|
||||
date: getToday(),
|
||||
userId,
|
||||
text,
|
||||
taskId,
|
||||
});
|
||||
@@ -225,11 +236,13 @@ export class DailyService {
|
||||
* Ajoute une checkbox pour hier
|
||||
*/
|
||||
async addYesterdayCheckbox(
|
||||
userId: string,
|
||||
text: string,
|
||||
taskId?: string
|
||||
): Promise<DailyCheckbox> {
|
||||
return this.addCheckbox({
|
||||
date: getYesterday(),
|
||||
userId,
|
||||
text,
|
||||
taskId,
|
||||
});
|
||||
@@ -239,7 +252,9 @@ export class DailyService {
|
||||
* Mappe une checkbox Prisma vers notre interface
|
||||
*/
|
||||
private mapPrismaCheckbox(
|
||||
checkbox: Prisma.DailyCheckboxGetPayload<{ include: { task: true } }>
|
||||
checkbox: Prisma.DailyCheckboxGetPayload<{
|
||||
include: { task: true; user: true };
|
||||
}>
|
||||
): DailyCheckbox {
|
||||
return {
|
||||
id: checkbox.id,
|
||||
@@ -249,6 +264,7 @@ export class DailyService {
|
||||
type: checkbox.type as DailyCheckboxType,
|
||||
order: checkbox.order,
|
||||
taskId: checkbox.taskId || undefined,
|
||||
userId: checkbox.userId,
|
||||
task: checkbox.task
|
||||
? {
|
||||
id: checkbox.task.id,
|
||||
@@ -334,7 +350,7 @@ export class DailyService {
|
||||
|
||||
const checkboxes = await prisma.dailyCheckbox.findMany({
|
||||
where: whereConditions,
|
||||
include: { task: true },
|
||||
include: { task: true, user: true },
|
||||
orderBy: [{ date: 'desc' }, { order: 'asc' }],
|
||||
...(options?.limit ? { take: options.limit } : {}),
|
||||
});
|
||||
@@ -356,7 +372,7 @@ export class DailyService {
|
||||
?.text + ' [ARCHIVÉ]',
|
||||
updatedAt: new Date(),
|
||||
},
|
||||
include: { task: true },
|
||||
include: { task: true, user: true },
|
||||
});
|
||||
|
||||
return this.mapPrismaCheckbox(checkbox);
|
||||
@@ -400,7 +416,7 @@ export class DailyService {
|
||||
order: newOrder,
|
||||
updatedAt: new Date(),
|
||||
},
|
||||
include: { task: true },
|
||||
include: { task: true, user: true },
|
||||
});
|
||||
|
||||
return this.mapPrismaCheckbox(updatedCheckbox);
|
||||
|
||||
Reference in New Issue
Block a user