Fix Panics with Short Task IDs

This commit is contained in:
BloxerHD 2026-02-24 22:54:32 +00:00
commit a8f93606df

View file

@ -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)