Fix Panics with Short Task IDs
This commit is contained in:
parent
1b6b7ea8bc
commit
a8f93606df
1 changed files with 6 additions and 1 deletions
|
|
@ -26,10 +26,15 @@ pub async fn get_all_tasks(pool: &Pool, allow_deleted: bool) -> Vec<Task> {
|
|||
}
|
||||
|
||||
pub async fn get_task(pool: &Pool, boss_app_id: String, task_id: String) -> Option<Task> {
|
||||
let task_id_end = task_id
|
||||
.char_indices()
|
||||
.nth(7)
|
||||
.map(|(i, _)| i)
|
||||
.unwrap_or_else(|| task_id.len());
|
||||
sqlx::query_as!(
|
||||
Task,
|
||||
"SELECT * FROM tasks WHERE deleted = false AND id = $1 AND boss_app_id = $2",
|
||||
&task_id[0..7],
|
||||
&task_id[..task_id_end],
|
||||
boss_app_id,
|
||||
)
|
||||
.fetch_optional(pool)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue