feat: prompt vehicle selection on login after auto-downgrade (#60) #62
@@ -28,7 +28,12 @@ export class VehiclesController {
|
|||||||
async getUserVehicles(request: FastifyRequest, reply: FastifyReply) {
|
async getUserVehicles(request: FastifyRequest, reply: FastifyReply) {
|
||||||
try {
|
try {
|
||||||
const userId = (request as any).user.sub;
|
const userId = (request as any).user.sub;
|
||||||
const vehicles = await this.vehiclesService.getUserVehicles(userId);
|
// Use tier-aware method to filter out locked vehicles after downgrade
|
||||||
|
const vehiclesWithStatus = await this.vehiclesService.getUserVehiclesWithTierStatus(userId);
|
||||||
|
// Only return active vehicles (filter out locked ones)
|
||||||
|
const vehicles = vehiclesWithStatus
|
||||||
|
.filter(v => v.tierStatus === 'active')
|
||||||
|
.map(({ tierStatus, ...vehicle }) => vehicle);
|
||||||
|
|
||||||
return reply.code(200).send(vehicles);
|
return reply.code(200).send(vehicles);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -108,6 +113,20 @@ export class VehiclesController {
|
|||||||
const userId = (request as any).user.sub;
|
const userId = (request as any).user.sub;
|
||||||
const { id } = request.params;
|
const { id } = request.params;
|
||||||
|
|
||||||
|
// Check tier status - block access to locked vehicles
|
||||||
|
const vehiclesWithStatus = await this.vehiclesService.getUserVehiclesWithTierStatus(userId);
|
||||||
|
const vehicleStatus = vehiclesWithStatus.find(v => v.id === id);
|
||||||
|
if (vehicleStatus && vehicleStatus.tierStatus === 'locked') {
|
||||||
|
return reply.code(403).send({
|
||||||
|
error: 'TIER_REQUIRED',
|
||||||
|
requiredTier: 'pro',
|
||||||
|
feature: 'vehicle.access',
|
||||||
|
featureName: 'Vehicle Access',
|
||||||
|
upgradePrompt: 'Upgrade to Pro to access all your vehicles',
|
||||||
|
message: 'This vehicle is not available on your current subscription tier'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
const vehicle = await this.vehiclesService.getVehicle(id, userId);
|
const vehicle = await this.vehiclesService.getVehicle(id, userId);
|
||||||
|
|
||||||
return reply.code(200).send(vehicle);
|
return reply.code(200).send(vehicle);
|
||||||
|
|||||||
Reference in New Issue
Block a user