feat: Add tier-based vehicle limit enforcement (#23) #25

Merged
egullickson merged 2 commits from issue-23-vehicle-limit-enforcement into main 2026-01-12 00:13:22 +00:00
Showing only changes of commit 8703e7758a - Show all commits

View File

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