Fixed task update

This commit is contained in:
Marcin-Ramotowski 2025-04-30 17:02:39 +00:00
parent acf3f75fc7
commit c728956099
2 changed files with 19 additions and 2 deletions

View File

@ -106,5 +106,5 @@ def validate_task_data(task):
except ValueError: except ValueError:
abort(400, "Incorrect datetime format. Expected DD-MM-YYYY HH:MM") abort(400, "Incorrect datetime format. Expected DD-MM-YYYY HH:MM")
done = task.get('done') done = task.get('done')
if done not in (0, 1): if done is not None and done not in (0, 1):
abort(400, "Incorrect done field value. Expected 0 or 1") abort(400, "Incorrect done field value. Expected 0 or 1")

View File

@ -100,7 +100,24 @@ const Tasks = () => {
const handleSaveEdit = async (taskId: number) => { const handleSaveEdit = async (taskId: number) => {
try { try {
const response = await api.patch(`/tasks/${taskId}`, editedTask); const formatDateForApi = (dateStr: string): string => {
const date = new Date(dateStr);
const day = String(date.getDate()).padStart(2, '0');
const month = String(date.getMonth() + 1).padStart(2, '0');
const year = date.getFullYear();
const hours = String(date.getHours()).padStart(2, '0');
const minutes = String(date.getMinutes()).padStart(2, '0');
return `${day}-${month}-${year} ${hours}:${minutes}`;
};
const payload = {
...editedTask,
due_date: editedTask.due_date
? formatDateForApi(editedTask.due_date)
: undefined,
};
const response = await api.patch(`/tasks/${taskId}`, payload);
setTasks(tasks.map((t) => (t.id === taskId ? response.data : t))); setTasks(tasks.map((t) => (t.id === taskId ? response.data : t)));
setEditingTaskId(null); setEditingTaskId(null);
setEditedTask({}); setEditedTask({});