feat: trim values from text input fields

This commit is contained in:
2024-09-19 20:41:50 +02:00
parent 905b2f4715
commit 934b5176c1
3 changed files with 25 additions and 1 deletions

View File

@ -17,6 +17,10 @@ use crate::server::subtasks::restore_subtasks_of_task;
pub(crate) async fn create_task(new_task: NewTask)
-> Result<Task, ServerFnError<ErrorVec<TaskError>>> {
use crate::schema::tasks;
// TODO: replace with model sanitization (https://github.com/matous-volf/todo-baggins/issues/13)
let mut new_task = new_task;
new_task.title = new_task.title.trim().to_owned();
new_task.validate()
.map_err::<ErrorVec<TaskError>, _>(|errors| errors.into())?;
@ -105,10 +109,14 @@ pub(crate) async fn get_tasks_with_subtasks_in_category(filtered_category: Categ
}
#[server]
pub(crate) async fn edit_task(task_id: i32, new_task: NewTask)
pub(crate) async fn edit_task(task_id: i32, mut new_task: NewTask)
-> Result<Task, ServerFnError<ErrorVec<TaskError>>> {
use crate::schema::tasks::dsl::*;
// TODO: replace with model sanitization (https://github.com/matous-volf/todo-baggins/issues/13)
let mut new_task = new_task;
new_task.title = new_task.title.trim().to_owned();
new_task.validate()
.map_err::<ErrorVec<TaskError>, _>(|errors| errors.into())?;