Fixing service registration that has no id

This commit is contained in:
2026-06-11 16:27:44 -04:00
parent 5e1d70128b
commit be6b933765
2 changed files with 6 additions and 4 deletions
+2 -1
View File
@@ -261,9 +261,10 @@ pub async fn register_service_user(
println!("Creating user"); println!("Creating user");
match repo::service::insert(&pool, &service_user).await { match repo::service::insert(&pool, &service_user).await {
Ok(created) => { Ok((service_user_id, created)) => {
resp.message = String::from(super::messages::SUCCESSFUL_MESSAGE); resp.message = String::from(super::messages::SUCCESSFUL_MESSAGE);
service_user.created = Some(created); service_user.created = Some(created);
service_user.id = service_user_id;
resp.data.push(service_user); resp.data.push(service_user);
(axum::http::StatusCode::CREATED, axum::Json(resp)) (axum::http::StatusCode::CREATED, axum::Json(resp))
} }
+4 -3
View File
@@ -111,11 +111,11 @@ pub async fn update_last_login(
pub async fn insert( pub async fn insert(
pool: &sqlx::PgPool, pool: &sqlx::PgPool,
service_user: &textsender_models::user::ServiceUser, service_user: &textsender_models::user::ServiceUser,
) -> Result<time::OffsetDateTime, sqlx::Error> { ) -> Result<(uuid::Uuid, time::OffsetDateTime), sqlx::Error> {
match sqlx::query( match sqlx::query(
r#"INSERT INTO "service_user" (username, passphrase, salt_id) r#"INSERT INTO "service_user" (username, passphrase, salt_id)
VALUES ($1, $2, $3) VALUES ($1, $2, $3)
RETURNING created RETURNING id, created
"#, "#,
) )
.bind(&service_user.username) .bind(&service_user.username)
@@ -125,8 +125,9 @@ pub async fn insert(
.await .await
{ {
Ok(row) => { Ok(row) => {
let id: uuid::Uuid = row.try_get("id")?;
let created: time::OffsetDateTime = row.try_get("created")?; let created: time::OffsetDateTime = row.try_get("created")?;
Ok(created) Ok((id, created))
} }
Err(err) => Err(err), Err(err) => Err(err),
} }