refactor: date utils and all calls
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { prisma } from './database';
|
||||
import { Prisma } from '@prisma/client';
|
||||
import { DailyCheckbox, DailyView, CreateDailyCheckboxData, UpdateDailyCheckboxData, BusinessError, DailyCheckboxType, TaskStatus, TaskPriority, TaskSource } from '@/lib/types';
|
||||
import { getPreviousWorkday } from '@/lib/workday-utils';
|
||||
import { getPreviousWorkday, normalizeDate, formatDateForAPI } from '@/lib/date-utils';
|
||||
|
||||
/**
|
||||
* Service pour la gestion des checkboxes daily
|
||||
@@ -13,8 +13,7 @@ export class DailyService {
|
||||
*/
|
||||
async getDailyView(date: Date): Promise<DailyView> {
|
||||
// Normaliser la date (début de journée)
|
||||
const today = new Date(date);
|
||||
today.setHours(0, 0, 0, 0);
|
||||
const today = normalizeDate(date);
|
||||
|
||||
// Utiliser la logique de jour de travail précédent au lieu de jour-1
|
||||
const yesterday = getPreviousWorkday(today);
|
||||
@@ -37,8 +36,7 @@ export class DailyService {
|
||||
*/
|
||||
async getCheckboxesByDate(date: Date): Promise<DailyCheckbox[]> {
|
||||
// Normaliser la date (début de journée)
|
||||
const normalizedDate = new Date(date);
|
||||
normalizedDate.setHours(0, 0, 0, 0);
|
||||
const normalizedDate = normalizeDate(date);
|
||||
|
||||
const checkboxes = await prisma.dailyCheckbox.findMany({
|
||||
where: { date: normalizedDate },
|
||||
@@ -54,8 +52,7 @@ export class DailyService {
|
||||
*/
|
||||
async addCheckbox(data: CreateDailyCheckboxData): Promise<DailyCheckbox> {
|
||||
// Normaliser la date
|
||||
const normalizedDate = new Date(data.date);
|
||||
normalizedDate.setHours(0, 0, 0, 0);
|
||||
const normalizedDate = normalizeDate(data.date);
|
||||
|
||||
// Calculer l'ordre suivant pour cette date
|
||||
const maxOrder = await prisma.dailyCheckbox.aggregate({
|
||||
@@ -128,10 +125,6 @@ export class DailyService {
|
||||
* Réordonne les checkboxes d'une date donnée
|
||||
*/
|
||||
async reorderCheckboxes(date: Date, checkboxIds: string[]): Promise<void> {
|
||||
// Normaliser la date
|
||||
const normalizedDate = new Date(date);
|
||||
normalizedDate.setHours(0, 0, 0, 0);
|
||||
|
||||
await prisma.$transaction(async (prisma) => {
|
||||
for (let i = 0; i < checkboxIds.length; i++) {
|
||||
await prisma.dailyCheckbox.update({
|
||||
@@ -264,11 +257,7 @@ export class DailyService {
|
||||
});
|
||||
|
||||
return checkboxes.map(checkbox => {
|
||||
const date = checkbox.date;
|
||||
const year = date.getFullYear();
|
||||
const month = String(date.getMonth() + 1).padStart(2, '0');
|
||||
const day = String(date.getDate()).padStart(2, '0');
|
||||
return `${year}-${month}-${day}`;
|
||||
return formatDateForAPI(checkbox.date);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
import { JiraTask } from '@/lib/types';
|
||||
import { prisma } from './database';
|
||||
import { parseDate } from '@/lib/date-utils';
|
||||
|
||||
export interface JiraConfig {
|
||||
baseUrl: string;
|
||||
@@ -339,12 +340,12 @@ export class JiraService {
|
||||
priority: this.mapJiraPriorityToInternal(jiraTask.priority?.name),
|
||||
source: 'jira' as const,
|
||||
sourceId: jiraTask.id,
|
||||
dueDate: jiraTask.duedate ? new Date(jiraTask.duedate) : null,
|
||||
dueDate: jiraTask.duedate ? parseDate(jiraTask.duedate) : null,
|
||||
jiraProject: jiraTask.project.key,
|
||||
jiraKey: jiraTask.key,
|
||||
jiraType: this.mapJiraTypeToDisplay(jiraTask.issuetype.name),
|
||||
assignee: jiraTask.assignee?.displayName || null,
|
||||
updatedAt: new Date(jiraTask.updated)
|
||||
updatedAt: parseDate(jiraTask.updated)
|
||||
};
|
||||
|
||||
if (!existingTask) {
|
||||
@@ -352,7 +353,7 @@ export class JiraService {
|
||||
const newTask = await prisma.task.create({
|
||||
data: {
|
||||
...taskData,
|
||||
createdAt: new Date(jiraTask.created)
|
||||
createdAt: parseDate(jiraTask.created)
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { prisma } from './database';
|
||||
import { startOfWeek, endOfWeek, eachDayOfInterval, format, startOfDay, endOfDay } from 'date-fns';
|
||||
import { fr } from 'date-fns/locale';
|
||||
import { formatDateForAPI, getDayName, getToday } from '@/lib/date-utils';
|
||||
|
||||
export interface DailyMetrics {
|
||||
date: string; // Format ISO
|
||||
@@ -58,7 +59,7 @@ export class MetricsService {
|
||||
/**
|
||||
* Récupère les métriques journalières de la semaine
|
||||
*/
|
||||
static async getWeeklyMetrics(date: Date = new Date()): Promise<WeeklyMetricsOverview> {
|
||||
static async getWeeklyMetrics(date: Date = getToday()): Promise<WeeklyMetricsOverview> {
|
||||
const weekStart = startOfWeek(date, { weekStartsOn: 1 }); // Lundi
|
||||
const weekEnd = endOfWeek(date, { weekStartsOn: 1 }); // Dimanche
|
||||
|
||||
@@ -163,8 +164,8 @@ export class MetricsService {
|
||||
const completionRate = totalTasks > 0 ? (completed / totalTasks) * 100 : 0;
|
||||
|
||||
return {
|
||||
date: date.toISOString(),
|
||||
dayName: format(date, 'EEEE', { locale: fr }),
|
||||
date: formatDateForAPI(date),
|
||||
dayName: getDayName(date),
|
||||
completed,
|
||||
inProgress,
|
||||
blocked,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { prisma } from './database';
|
||||
import { Task, TaskStatus, TaskPriority, TaskSource, BusinessError, DailyCheckbox, DailyCheckboxType } from '@/lib/types';
|
||||
import { Prisma } from '@prisma/client';
|
||||
import { getToday } from '@/lib/date-utils';
|
||||
|
||||
/**
|
||||
* Service pour la gestion des tâches (version standalone)
|
||||
@@ -126,12 +127,12 @@ export class TasksService {
|
||||
status: updates.status,
|
||||
priority: updates.priority,
|
||||
dueDate: updates.dueDate,
|
||||
updatedAt: new Date()
|
||||
updatedAt: getToday()
|
||||
};
|
||||
|
||||
|
||||
if (updates.status === 'done' && !task.completedAt) {
|
||||
updateData.completedAt = new Date();
|
||||
updateData.completedAt = getToday();
|
||||
} else if (updates.status && updates.status !== 'done' && task.completedAt) {
|
||||
updateData.completedAt = null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user