fix: profile approval 500 — users table has no role column
All checks were successful
build-and-release / build (employees) (push) Successful in 11s
build-and-release / build (cron) (push) Successful in 13s
build-and-release / build (catering-services) (push) Successful in 17s
build-and-release / build (companies) (push) Successful in 17s
build-and-release / build (customers) (push) Successful in 17s
build-and-release / build (developers) (push) Successful in 16s
build-and-release / build (fitness-trainers) (push) Successful in 5s
build-and-release / build (graphic-designers) (push) Successful in 7s
build-and-release / build (gateway) (push) Successful in 7s
build-and-release / build (job-seekers) (push) Successful in 7s
build-and-release / build (jobs) (push) Successful in 8s
build-and-release / build (payments) (push) Successful in 7s
build-and-release / build (makeup-artists) (push) Successful in 10s
build-and-release / build (photographers) (push) Successful in 7s
build-and-release / build (social-media-managers) (push) Successful in 8s
build-and-release / build (tutors) (push) Successful in 8s
build-and-release / build (ugc-content-creators) (push) Successful in 7s
build-and-release / build (video-editors) (push) Successful in 8s
build-and-release / build (users) (push) Successful in 2m45s

activate_profile_after_final_approval ran UPDATE users SET role = $1,
but users only has role_id (FK into roles), never a plain role column.
Resolve the role's id via RoleRepository::get_by_key first and update
role_id instead, matching how role is tracked everywhere else.
This commit is contained in:
Ashwin Kumar Sivakumar 2026-07-31 16:52:33 +05:30
parent 2f47308498
commit b281eb5278

View file

@ -223,16 +223,17 @@ async fn activate_profile_after_final_approval(
sqlx::query(&query).bind(user_role_profile_id).execute(&state.pool).await?;
}
// Update user's role to match the approved role_key and set status to ACTIVE
sqlx::query(
"UPDATE users SET role = $1, status = 'ACTIVE', updated_at = NOW() WHERE id = $2",
)
.bind(&role_key)
.bind(user_id)
.execute(&state.pool)
.await?;
// Update user's role to match the approved role_key and set status to ACTIVE.
// `users` has no `role` text column — role is tracked via `role_id` FK into `roles`.
if let Ok(role) = RoleRepository::get_by_key(&state.pool, &role_key).await {
sqlx::query(
"UPDATE users SET role_id = $1, status = 'ACTIVE', updated_at = NOW() WHERE id = $2",
)
.bind(role.id)
.bind(user_id)
.execute(&state.pool)
.await?;
sqlx::query(
"INSERT INTO user_role_assignments (user_id, role_id, status, approved_at) VALUES ($1, $2, 'APPROVED', NOW()) ON CONFLICT (user_id, role_id) DO UPDATE SET status = 'APPROVED', approved_at = NOW()",
)