fix(backend): add 404 error when not found in resource delete endpoints (#7036)

This commit is contained in:
hugocasa
2025-11-03 15:10:36 +01:00
committed by GitHub
parent e5b8363e20
commit eccdeeebed
4 changed files with 56 additions and 21 deletions

View File

@@ -0,0 +1,23 @@
{
"db_name": "PostgreSQL",
"query": "DELETE FROM resource_type WHERE name = $1 AND workspace_id = $2 RETURNING name",
"describe": {
"columns": [
{
"ordinal": 0,
"name": "name",
"type_info": "Varchar"
}
],
"parameters": {
"Left": [
"Text",
"Text"
]
},
"nullable": [
false
]
},
"hash": "1d9498226b3d962688558d8ab77f88de5dc8ae5321fa7ff0c7632e628556f991"
}

View File

@@ -0,0 +1,23 @@
{
"db_name": "PostgreSQL",
"query": "DELETE FROM resource WHERE path = $1 AND workspace_id = $2 RETURNING path",
"describe": {
"columns": [
{
"ordinal": 0,
"name": "path",
"type_info": "Varchar"
}
],
"parameters": {
"Left": [
"Text",
"Text"
]
},
"nullable": [
false
]
},
"hash": "85ec6c6384ab77df102d05caf82079e65a5300a52a292b9143b755087b9f9c4c"
}

View File

@@ -1,15 +0,0 @@
{
"db_name": "PostgreSQL",
"query": "DELETE FROM resource_type WHERE name = $1 AND workspace_id = $2",
"describe": {
"columns": [],
"parameters": {
"Left": [
"Text",
"Text"
]
},
"nullable": []
},
"hash": "d5d97005eebcb2760216dbd10872acdb42868fd5f7a27f71836e7a6ff1c69856"
}

View File

@@ -798,13 +798,14 @@ async fn delete_resource(
check_scopes(&authed, || format!("resources:write:{}", path))?;
let mut tx = user_db.begin(&authed).await?;
sqlx::query!(
"DELETE FROM resource WHERE path = $1 AND workspace_id = $2",
let deleted_path = sqlx::query_scalar!(
"DELETE FROM resource WHERE path = $1 AND workspace_id = $2 RETURNING path",
path,
w_id
)
.execute(&mut *tx)
.fetch_optional(&mut *tx)
.await?;
not_found_if_none(deleted_path, "Resource", &path)?;
sqlx::query!(
"DELETE FROM variable WHERE path = $1 AND workspace_id = $2",
path,
@@ -1248,13 +1249,16 @@ async fn delete_resource_type(
let mut tx = user_db.begin(&authed).await?;
sqlx::query!(
"DELETE FROM resource_type WHERE name = $1 AND workspace_id = $2",
let deleted_name = sqlx::query_scalar!(
"DELETE FROM resource_type WHERE name = $1 AND workspace_id = $2 RETURNING name",
name,
w_id
)
.execute(&mut *tx)
.fetch_optional(&mut *tx)
.await?;
not_found_if_none(deleted_name, "ResourceType", &name)?;
audit_log(
&mut *tx,
&authed,