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