chore: prettier everywhere

This commit is contained in:
Julien Froidefond
2025-10-09 13:40:03 +02:00
parent f8100ae3e9
commit d9cf9a2655
303 changed files with 15420 additions and 9391 deletions

View File

@@ -1,13 +1,28 @@
import { prisma } from '@/services/core/database';
import { Prisma } from '@prisma/client';
import { DailyCheckbox, DailyView, CreateDailyCheckboxData, UpdateDailyCheckboxData, BusinessError, DailyCheckboxType, TaskStatus, TaskPriority, TaskSource } from '@/lib/types';
import { getPreviousWorkday, normalizeDate, formatDateForAPI, getToday, getYesterday } from '@/lib/date-utils';
import {
DailyCheckbox,
DailyView,
CreateDailyCheckboxData,
UpdateDailyCheckboxData,
BusinessError,
DailyCheckboxType,
TaskStatus,
TaskPriority,
TaskSource,
} from '@/lib/types';
import {
getPreviousWorkday,
normalizeDate,
formatDateForAPI,
getToday,
getYesterday,
} from '@/lib/date-utils';
/**
* Service pour la gestion des checkboxes daily
*/
export class DailyService {
/**
* Récupère la vue daily pour une date donnée (checkboxes d'hier et d'aujourd'hui)
*/
@@ -21,13 +36,13 @@ 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(today),
]);
return {
date: today,
yesterday: yesterdayCheckboxes,
today: todayCheckboxes
today: todayCheckboxes,
};
}
@@ -41,7 +56,7 @@ export class DailyService {
const checkboxes = await prisma.dailyCheckbox.findMany({
where: { date: normalizedDate },
include: { task: true },
orderBy: { order: 'asc' }
orderBy: { order: 'asc' },
});
return checkboxes.map(this.mapPrismaCheckbox);
@@ -57,10 +72,10 @@ export class DailyService {
// Calculer l'ordre suivant pour cette date
const maxOrder = await prisma.dailyCheckbox.aggregate({
where: { date: normalizedDate },
_max: { order: true }
_max: { order: true },
});
const order = data.order ?? ((maxOrder._max.order ?? -1) + 1);
const order = data.order ?? (maxOrder._max.order ?? -1) + 1;
const checkbox = await prisma.dailyCheckbox.create({
data: {
@@ -69,9 +84,9 @@ export class DailyService {
type: data.type ?? 'task',
taskId: data.taskId,
order,
isChecked: data.isChecked ?? false
isChecked: data.isChecked ?? false,
},
include: { task: true }
include: { task: true },
});
return this.mapPrismaCheckbox(checkbox);
@@ -80,7 +95,10 @@ export class DailyService {
/**
* Met à jour une checkbox
*/
async updateCheckbox(checkboxId: string, data: UpdateDailyCheckboxData): Promise<DailyCheckbox> {
async updateCheckbox(
checkboxId: string,
data: UpdateDailyCheckboxData
): Promise<DailyCheckbox> {
const updateData: Prisma.DailyCheckboxUpdateInput = {};
if (data.text !== undefined) updateData.text = data.text.trim();
@@ -99,7 +117,7 @@ export class DailyService {
const checkbox = await prisma.dailyCheckbox.update({
where: { id: checkboxId },
data: updateData,
include: { task: true }
include: { task: true },
});
return this.mapPrismaCheckbox(checkbox);
@@ -110,7 +128,7 @@ export class DailyService {
*/
async deleteCheckbox(checkboxId: string): Promise<void> {
const checkbox = await prisma.dailyCheckbox.findUnique({
where: { id: checkboxId }
where: { id: checkboxId },
});
if (!checkbox) {
@@ -118,7 +136,7 @@ export class DailyService {
}
await prisma.dailyCheckbox.delete({
where: { id: checkboxId }
where: { id: checkboxId },
});
}
@@ -130,7 +148,7 @@ export class DailyService {
for (let i = 0; i < checkboxIds.length; i++) {
await prisma.dailyCheckbox.update({
where: { id: checkboxIds[i] },
data: { order: i }
data: { order: i },
});
}
});
@@ -139,16 +157,19 @@ export class DailyService {
/**
* Recherche dans les checkboxes
*/
async searchCheckboxes(query: string, limit: number = 20): Promise<DailyCheckbox[]> {
async searchCheckboxes(
query: string,
limit: number = 20
): Promise<DailyCheckbox[]> {
const checkboxes = await prisma.dailyCheckbox.findMany({
where: {
text: {
contains: query
}
contains: query,
},
},
include: { task: true },
orderBy: { date: 'desc' },
take: limit
take: limit,
});
return checkboxes.map(this.mapPrismaCheckbox);
@@ -157,13 +178,15 @@ export class DailyService {
/**
* Récupère l'historique des checkboxes (groupées par date)
*/
async getCheckboxHistory(limit: number = 30): Promise<{ date: Date; checkboxes: DailyCheckbox[] }[]> {
async getCheckboxHistory(
limit: number = 30
): Promise<{ date: Date; checkboxes: DailyCheckbox[] }[]> {
// Récupérer les dates distinctes des dernières checkboxes
const distinctDates = await prisma.dailyCheckbox.findMany({
select: { date: true },
distinct: ['date'],
orderBy: { date: 'desc' },
take: limit
take: limit,
});
const history = [];
@@ -187,29 +210,37 @@ export class DailyService {
/**
* Ajoute une checkbox pour aujourd'hui
*/
async addTodayCheckbox(text: string, taskId?: string): Promise<DailyCheckbox> {
async addTodayCheckbox(
text: string,
taskId?: string
): Promise<DailyCheckbox> {
return this.addCheckbox({
date: getToday(),
text,
taskId
taskId,
});
}
/**
* Ajoute une checkbox pour hier
*/
async addYesterdayCheckbox(text: string, taskId?: string): Promise<DailyCheckbox> {
async addYesterdayCheckbox(
text: string,
taskId?: string
): Promise<DailyCheckbox> {
return this.addCheckbox({
date: getYesterday(),
text,
taskId
taskId,
});
}
/**
* Mappe une checkbox Prisma vers notre interface
*/
private mapPrismaCheckbox(checkbox: Prisma.DailyCheckboxGetPayload<{ include: { task: true } }>): DailyCheckbox {
private mapPrismaCheckbox(
checkbox: Prisma.DailyCheckboxGetPayload<{ include: { task: true } }>
): DailyCheckbox {
return {
id: checkbox.id,
date: checkbox.date,
@@ -218,26 +249,28 @@ export class DailyService {
type: checkbox.type as DailyCheckboxType,
order: checkbox.order,
taskId: checkbox.taskId || undefined,
task: checkbox.task ? {
id: checkbox.task.id,
title: checkbox.task.title,
description: checkbox.task.description || undefined,
status: checkbox.task.status as TaskStatus,
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
dueDate: checkbox.task.dueDate || undefined,
completedAt: checkbox.task.completedAt || undefined,
createdAt: checkbox.task.createdAt,
updatedAt: checkbox.task.updatedAt,
jiraProject: checkbox.task.jiraProject || undefined,
jiraKey: checkbox.task.jiraKey || undefined,
assignee: checkbox.task.assignee || undefined
} : undefined,
task: checkbox.task
? {
id: checkbox.task.id,
title: checkbox.task.title,
description: checkbox.task.description || undefined,
status: checkbox.task.status as TaskStatus,
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
dueDate: checkbox.task.dueDate || undefined,
completedAt: checkbox.task.completedAt || undefined,
createdAt: checkbox.task.createdAt,
updatedAt: checkbox.task.updatedAt,
jiraProject: checkbox.task.jiraProject || undefined,
jiraKey: checkbox.task.jiraKey || undefined,
assignee: checkbox.task.assignee || undefined,
}
: undefined,
isArchived: checkbox.text.includes('[ARCHIVÉ]'),
createdAt: checkbox.createdAt,
updatedAt: checkbox.updatedAt
updatedAt: checkbox.updatedAt,
};
}
@@ -247,15 +280,15 @@ export class DailyService {
async getDailyDates(): Promise<string[]> {
const checkboxes = await prisma.dailyCheckbox.findMany({
select: {
date: true
date: true,
},
distinct: ['date'],
orderBy: {
date: 'desc'
}
date: 'desc',
},
});
return checkboxes.map(checkbox => {
return checkboxes.map((checkbox) => {
return formatDateForAPI(checkbox.date);
});
}
@@ -272,7 +305,7 @@ export class DailyService {
const today = normalizeDate(getToday());
const maxDays = options?.maxDays ?? 30;
const excludeToday = options?.excludeToday ?? true;
// Calculer la date limite (maxDays jours en arrière)
const limitDate = new Date(today);
limitDate.setDate(limitDate.getDate() - maxDays);
@@ -290,8 +323,8 @@ export class DailyService {
isChecked: false,
date: {
gte: limitDate,
...(excludeToday ? { lt: today } : { lte: today })
}
...(excludeToday ? { lt: today } : { lte: today }),
},
};
// Filtrer par type si spécifié
@@ -302,11 +335,8 @@ export class DailyService {
const checkboxes = await prisma.dailyCheckbox.findMany({
where: whereConditions,
include: { task: true },
orderBy: [
{ date: 'desc' },
{ order: 'asc' }
],
...(options?.limit ? { take: options.limit } : {})
orderBy: [{ date: 'desc' }, { order: 'asc' }],
...(options?.limit ? { take: options.limit } : {}),
});
return checkboxes.map(this.mapPrismaCheckbox);
@@ -320,11 +350,13 @@ export class DailyService {
// Plus tard on pourra ajouter un champ dédié dans la DB
const checkbox = await prisma.dailyCheckbox.update({
where: { id: checkboxId },
data: {
text: (await prisma.dailyCheckbox.findUnique({ where: { id: checkboxId } }))?.text + ' [ARCHIVÉ]',
updatedAt: new Date()
data: {
text:
(await prisma.dailyCheckbox.findUnique({ where: { id: checkboxId } }))
?.text + ' [ARCHIVÉ]',
updatedAt: new Date(),
},
include: { task: true }
include: { task: true },
});
return this.mapPrismaCheckbox(checkbox);
@@ -335,7 +367,7 @@ export class DailyService {
*/
async moveCheckboxToToday(checkboxId: string): Promise<DailyCheckbox> {
const checkbox = await prisma.dailyCheckbox.findUnique({
where: { id: checkboxId }
where: { id: checkboxId },
});
if (!checkbox) {
@@ -347,28 +379,28 @@ export class DailyService {
}
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');
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 }
_max: { order: true },
});
const newOrder = (maxOrder._max.order ?? -1) + 1;
const updatedCheckbox = await prisma.dailyCheckbox.update({
where: { id: checkboxId },
data: {
data: {
date: today,
order: newOrder,
updatedAt: new Date()
updatedAt: new Date(),
},
include: { task: true }
include: { task: true },
});
return this.mapPrismaCheckbox(updatedCheckbox);
@@ -376,4 +408,4 @@ export class DailyService {
}
// Instance singleton du service
export const dailyService = new DailyService();
export const dailyService = new DailyService();