feat: Add tier-based vehicle limit enforcement (#23) #25
@@ -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)) {
|
||||
|
||||
Reference in New Issue
Block a user