feat: text input value trimming (#57)
This commit is contained in:
		| @@ -12,6 +12,10 @@ pub(crate) async fn create_project(new_project: NewProject) | |||||||
|                                    -> Result<Project, ServerFnError<ErrorVec<ProjectError>>> { |                                    -> Result<Project, ServerFnError<ErrorVec<ProjectError>>> { | ||||||
|     use crate::schema::projects; |     use crate::schema::projects; | ||||||
|  |  | ||||||
|  |     // TODO: replace with model sanitization (https://github.com/matous-volf/todo-baggins/issues/13) | ||||||
|  |     let mut new_project = new_project; | ||||||
|  |     new_project.title = new_project.title.trim().to_owned(); | ||||||
|  |  | ||||||
|     new_project.validate() |     new_project.validate() | ||||||
|         .map_err::<ErrorVec<ProjectError>, _>(|errors| errors.into())?; |         .map_err::<ErrorVec<ProjectError>, _>(|errors| errors.into())?; | ||||||
|  |  | ||||||
| @@ -54,6 +58,10 @@ pub(crate) async fn edit_project(project_id: i32, new_project: NewProject) | |||||||
|                                  -> Result<Project, ServerFnError<ErrorVec<ProjectError>>> { |                                  -> Result<Project, ServerFnError<ErrorVec<ProjectError>>> { | ||||||
|     use crate::schema::projects::dsl::*; |     use crate::schema::projects::dsl::*; | ||||||
|  |  | ||||||
|  |     // TODO: replace with model sanitization (https://github.com/matous-volf/todo-baggins/issues/13) | ||||||
|  |     let mut new_project = new_project; | ||||||
|  |     new_project.title = new_project.title.trim().to_owned(); | ||||||
|  |  | ||||||
|     new_project.validate() |     new_project.validate() | ||||||
|         .map_err::<ErrorVec<ProjectError>, _>(|errors| errors.into())?; |         .map_err::<ErrorVec<ProjectError>, _>(|errors| errors.into())?; | ||||||
|  |  | ||||||
|   | |||||||
| @@ -13,6 +13,10 @@ pub(crate) async fn create_subtask(new_subtask: NewSubtask) | |||||||
|                                    -> Result<Subtask, ServerFnError<ErrorVec<SubtaskError>>> { |                                    -> Result<Subtask, ServerFnError<ErrorVec<SubtaskError>>> { | ||||||
|     use crate::schema::subtasks; |     use crate::schema::subtasks; | ||||||
|  |  | ||||||
|  |     // TODO: replace with model sanitization (https://github.com/matous-volf/todo-baggins/issues/13) | ||||||
|  |     let mut new_subtask = new_subtask; | ||||||
|  |     new_subtask.title = new_subtask.title.trim().to_owned(); | ||||||
|  |  | ||||||
|     new_subtask.validate() |     new_subtask.validate() | ||||||
|         .map_err::<ErrorVec<SubtaskError>, _>(|errors| errors.into())?; |         .map_err::<ErrorVec<SubtaskError>, _>(|errors| errors.into())?; | ||||||
|  |  | ||||||
| @@ -55,6 +59,10 @@ pub(crate) async fn edit_subtask(subtask_id: i32, new_subtask: NewSubtask) | |||||||
|                                  -> Result<Subtask, ServerFnError<ErrorVec<SubtaskError>>> { |                                  -> Result<Subtask, ServerFnError<ErrorVec<SubtaskError>>> { | ||||||
|     use crate::schema::subtasks::dsl::*; |     use crate::schema::subtasks::dsl::*; | ||||||
|  |  | ||||||
|  |     // TODO: replace with model sanitization (https://github.com/matous-volf/todo-baggins/issues/13) | ||||||
|  |     let mut new_subtask = new_subtask; | ||||||
|  |     new_subtask.title = new_subtask.title.trim().to_owned(); | ||||||
|  |  | ||||||
|     new_subtask.validate() |     new_subtask.validate() | ||||||
|         .map_err::<ErrorVec<SubtaskError>, _>(|errors| errors.into())?; |         .map_err::<ErrorVec<SubtaskError>, _>(|errors| errors.into())?; | ||||||
|  |  | ||||||
|   | |||||||
| @@ -17,6 +17,10 @@ use crate::server::subtasks::restore_subtasks_of_task; | |||||||
| pub(crate) async fn create_task(new_task: NewTask) | pub(crate) async fn create_task(new_task: NewTask) | ||||||
|                                 -> Result<Task, ServerFnError<ErrorVec<TaskError>>> { |                                 -> Result<Task, ServerFnError<ErrorVec<TaskError>>> { | ||||||
|     use crate::schema::tasks; |     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() |     new_task.validate() | ||||||
|         .map_err::<ErrorVec<TaskError>, _>(|errors| errors.into())?; |         .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] | #[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>>> { |                               -> Result<Task, ServerFnError<ErrorVec<TaskError>>> { | ||||||
|     use crate::schema::tasks::dsl::*; |     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() |     new_task.validate() | ||||||
|         .map_err::<ErrorVec<TaskError>, _>(|errors| errors.into())?; |         .map_err::<ErrorVec<TaskError>, _>(|errors| errors.into())?; | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user