fix slug colliding error not showing when editing project (#534)

* fix slug colliding error not showing when editing project

* format

* re-introduce old code

* run sqlx prepare

---------

Co-authored-by: MagnusHJensen <magnus.holm.jensen@lego.dk>
Co-authored-by: Geometrically <18202329+Geometrically@users.noreply.github.com>
This commit is contained in:
Magnus Jensen 2023-02-15 18:41:00 +01:00 committed by GitHub
parent 7ec518b41c
commit 8eb9fb1834
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 0 deletions

View File

@ -5047,6 +5047,26 @@
},
"query": "\n SELECT id FROM categories\n WHERE category = $1 AND project_type = $2\n "
},
"abf790170e3a807ffe8b3a188da620c89e6398f38ff066220fdadffe8e7481c1": {
"describe": {
"columns": [
{
"name": "exists",
"ordinal": 0,
"type_info": "Bool"
}
],
"nullable": [
null
],
"parameters": {
"Left": [
"Text"
]
}
},
"query": "\n SELECT EXISTS(SELECT 1 FROM mods WHERE slug = LOWER($1))\n "
},
"ac2d17b7d7147b14f072c15ffa214c14f32f27ffa6a3c2b2a5f80f3ad49ca5e9": {
"describe": {
"columns": [

View File

@ -894,6 +894,24 @@ pub async fn project_edit(
}
}
{
let results = sqlx::query!(
"
SELECT EXISTS(SELECT 1 FROM mods WHERE slug = LOWER($1))
",
slug
)
.fetch_one(&mut *transaction)
.await?;
if results.exists.unwrap_or(true) {
return Err(ApiError::InvalidInput(
"Slug collides with other project's id!"
.to_string(),
));
}
}
sqlx::query!(
"
UPDATE mods