Convert user and role IDs from number to UUID string

Updated backend and frontend to use UUID strings instead of integers for user and role IDs
to match PostgreSQL database schema (UUID type).

Backend changes:
- Updated User and UserPublic interfaces: id and role_id now string (UUID)
- Updated JwtPayload: userId and roleId now string
- Updated user validators: role_id validation changed from number to UUID string
- Removed parseInt() calls in user controller (getUserById, updateUser, deleteUser, changePassword)
- Updated all user service function signatures to accept string IDs
- Updated create() and update() functions to accept role_id as string

Frontend changes:
- Updated User interface in users API: role_id is string
- Updated CreateUserInput and UpdateUserInput: role_id is string
- Added role filter in UsersPage sidebar
- Removed number conversion logic (parseInt)

This fixes the "invalid input syntax for type uuid" error when creating/updating users.
This commit is contained in:
2026-01-26 19:49:15 -06:00
parent c910ce8996
commit 2d977b13b4
6 changed files with 193 additions and 183 deletions

View File

@@ -67,9 +67,9 @@ export async function getUserById(
res: Response
): Promise<void> {
try {
const userId = parseInt(req.params.id, 10);
const userId = req.params.id;
if (isNaN(userId)) {
if (!userId) {
res.status(400).json({
success: false,
error: 'Invalid user ID',
@@ -80,7 +80,7 @@ export async function getUserById(
// Check if user is admin or requesting their own data
const requestingUser = req.user;
const isAdmin = requestingUser?.role === 'ADMIN';
const isSelf = requestingUser?.id === userId.toString();
const isSelf = requestingUser?.id === userId;
if (!isAdmin && !isSelf) {
res.status(403).json({
@@ -166,9 +166,9 @@ export async function updateUser(
res: Response
): Promise<void> {
try {
const userId = parseInt(req.params.id, 10);
const userId = req.params.id;
if (isNaN(userId)) {
if (!userId) {
res.status(400).json({
success: false,
error: 'Invalid user ID',
@@ -178,7 +178,7 @@ export async function updateUser(
const requestingUser = req.user;
const isAdmin = requestingUser?.role === 'ADMIN';
const isSelf = requestingUser?.id === userId.toString();
const isSelf = requestingUser?.id === userId;
if (!isAdmin && !isSelf) {
res.status(403).json({
@@ -243,9 +243,9 @@ export async function deleteUser(
res: Response
): Promise<void> {
try {
const userId = parseInt(req.params.id, 10);
const userId = req.params.id;
if (isNaN(userId)) {
if (!userId) {
res.status(400).json({
success: false,
error: 'Invalid user ID',
@@ -254,7 +254,7 @@ export async function deleteUser(
}
// Prevent admin from deleting themselves
if (req.user?.id === userId.toString()) {
if (req.user?.id === userId) {
res.status(400).json({
success: false,
error: 'Cannot deactivate your own account',
@@ -294,9 +294,9 @@ export async function changePassword(
res: Response
): Promise<void> {
try {
const userId = parseInt(req.params.id, 10);
const userId = req.params.id;
if (isNaN(userId)) {
if (!userId) {
res.status(400).json({
success: false,
error: 'Invalid user ID',
@@ -305,7 +305,7 @@ export async function changePassword(
}
// Only allow users to change their own password
if (req.user?.id !== userId.toString()) {
if (req.user?.id !== userId) {
res.status(403).json({
success: false,
error: 'You can only change your own password',