Add delete/patch todos

This commit is contained in:
jude
2024-04-10 18:42:29 +01:00
parent 4063334953
commit 24e316b12f
5 changed files with 85 additions and 13 deletions

View File

@ -167,7 +167,7 @@ pub async fn update_todo(
"
UPDATE todos
SET value = ?
WHERE guild_id = ?
WHERE guild_id = (SELECT id FROM guilds WHERE guild = ?)
AND id = ?
",
todo.value,
@ -181,6 +181,11 @@ pub async fn update_todo(
json!({"errors": vec!["Unknown error"]})
})?;
if let Err(e) = transaction.commit().await {
warn!("Couldn't commit transaction: {:?}", e);
return json_err!("Couldn't commit transaction.");
}
Ok(json!({}))
}
@ -197,7 +202,7 @@ pub async fn delete_todo(
sqlx::query!(
"
DELETE FROM todos
WHERE guild_id = ?
WHERE guild_id = (SELECT id FROM guilds WHERE guild = ?)
AND id = ?
",
guild_id,
@ -210,5 +215,10 @@ pub async fn delete_todo(
json!({"errors": vec!["Unknown error"]})
})?;
if let Err(e) = transaction.commit().await {
warn!("Couldn't commit transaction: {:?}", e);
return json_err!("Couldn't commit transaction.");
}
Ok(json!({}))
}