Improve task date handling to prevent errors

Update task storage logic to correctly format and handle date values for PostgreSQL, preventing potential 500 errors caused by type mismatches and incorrect date parsing.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: cc2d271b-82f0-4d6a-9302-a0b067ffb429
Replit-Commit-Checkpoint-Type: full_checkpoint
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/1957c339-2757-4d1f-8e92-e9f71a1ce58e/cc2d271b-82f0-4d6a-9302-a0b067ffb429/U0y2tJ3
This commit is contained in:
michaelschal committed 2025-08-19 11:28:00 +00:00
1 parent 24b7d67745
commit 90480201ee
2 files changed
+21 -3

No files matched your search

Binary file not shown.

After

Width:  |  Height:  |  Size: 275 KiB

+21 -3
View File
@@ -1724,16 +1724,34 @@ export class DatabaseStorage implements IStorage {
if (taskData.priority !== undefined) cleanData.priority = taskData.priority;
if (taskData.status !== undefined) cleanData.status = taskData.status;
if (taskData.assignedTo !== undefined) cleanData.assignedTo = taskData.assignedTo;
// Gestion spéciale des dates selon les types PostgreSQL
if (taskData.startDate !== undefined) {
cleanData.startDate = taskData.startDate === '' || taskData.startDate === null ? null : taskData.startDate;
if (taskData.startDate === '' || taskData.startDate === null) {
cleanData.startDate = null;
} else {
// start_date est un timestamp en PostgreSQL - on peut passer une date
cleanData.startDate = new Date(taskData.startDate);
}
}
if (taskData.dueDate !== undefined) {
cleanData.dueDate = taskData.dueDate === '' || taskData.dueDate === null ? null : taskData.dueDate;
if (taskData.dueDate === '' || taskData.dueDate === null) {
cleanData.dueDate = null;
} else {
// due_date est un date en PostgreSQL - on passe la chaîne directement
cleanData.dueDate = taskData.dueDate;
}
}
cleanData.updatedAt = new Date();
console.log('🧹 Cleaned data for database update:', cleanData);
console.log('🧹 Cleaned data for database update:', {
...cleanData,
startDateType: cleanData.startDate ? typeof cleanData.startDate : 'null',
dueDateType: cleanData.dueDate ? typeof cleanData.dueDate : 'null',
startDateIsDate: cleanData.startDate instanceof Date,
});
try {
const [task] = await db