diff --git a/backend/src/features/vehicles/domain/vehicles.service.ts b/backend/src/features/vehicles/domain/vehicles.service.ts index a03ebc1..cde91b5 100644 --- a/backend/src/features/vehicles/domain/vehicles.service.ts +++ b/backend/src/features/vehicles/domain/vehicles.service.ts @@ -86,11 +86,12 @@ export class VehiclesService { await client.query('BEGIN'); // Lock user's vehicle rows and get count - const countResult = await client.query( - 'SELECT COUNT(*) as count FROM vehicles WHERE user_id = $1 AND is_active = true FOR UPDATE', + // Note: Cannot use COUNT(*) with FOR UPDATE, so we select IDs and count in app + const lockResult = await client.query( + 'SELECT id FROM vehicles WHERE user_id = $1 AND is_active = true FOR UPDATE', [userId] ); - const currentCount = parseInt(countResult.rows[0].count, 10); + const currentCount = lockResult.rows.length; // Check if user can add another vehicle if (!canAddVehicle(userTier, currentCount)) {