Add subcription level filtering
This commit is contained in:
@@ -4,9 +4,7 @@
|
||||
import { apiClient } from '../client';
|
||||
import {
|
||||
SubscriptionLimits,
|
||||
FeatureCheckRequest,
|
||||
FeatureCheckResponse,
|
||||
UsageCheckRequest,
|
||||
UsageCheckResponse,
|
||||
UsageSummary,
|
||||
AvailablePlans,
|
||||
@@ -68,45 +66,35 @@ export class SubscriptionService {
|
||||
}
|
||||
|
||||
async getUsageSummary(tenantId: string): Promise<UsageSummary> {
|
||||
try {
|
||||
return await apiClient.get<UsageSummary>(`${this.baseUrl}/${tenantId}/summary`);
|
||||
} catch (error) {
|
||||
// Return mock data if backend endpoint doesn't exist yet
|
||||
console.warn('Using mock subscription data - backend endpoint not implemented yet');
|
||||
return this.getMockUsageSummary();
|
||||
}
|
||||
return apiClient.get<UsageSummary>(`${this.baseUrl}/${tenantId}/usage`);
|
||||
}
|
||||
|
||||
async getAvailablePlans(): Promise<AvailablePlans> {
|
||||
try {
|
||||
return await apiClient.get<AvailablePlans>(`${this.baseUrl}/plans`);
|
||||
} catch (error) {
|
||||
// Return mock data if backend endpoint doesn't exist yet
|
||||
console.warn('Using mock plans data - backend endpoint not implemented yet');
|
||||
return this.getMockAvailablePlans();
|
||||
}
|
||||
return apiClient.get<AvailablePlans>('/subscriptions/plans');
|
||||
}
|
||||
|
||||
async validatePlanUpgrade(tenantId: string, planKey: string): Promise<PlanUpgradeValidation> {
|
||||
try {
|
||||
return await apiClient.post<PlanUpgradeValidation>(`${this.baseUrl}/${tenantId}/validate-upgrade`, {
|
||||
plan: planKey
|
||||
});
|
||||
} catch (error) {
|
||||
console.warn('Using mock validation - backend endpoint not implemented yet');
|
||||
return { can_upgrade: true };
|
||||
}
|
||||
return apiClient.get<PlanUpgradeValidation>(`${this.baseUrl}/${tenantId}/validate-upgrade/${planKey}`);
|
||||
}
|
||||
|
||||
async upgradePlan(tenantId: string, planKey: string): Promise<PlanUpgradeResult> {
|
||||
try {
|
||||
return await apiClient.post<PlanUpgradeResult>(`${this.baseUrl}/${tenantId}/upgrade`, {
|
||||
plan: planKey
|
||||
});
|
||||
} catch (error) {
|
||||
console.warn('Using mock upgrade - backend endpoint not implemented yet');
|
||||
return { success: true, message: 'Plan actualizado correctamente (modo demo)' };
|
||||
}
|
||||
return apiClient.post<PlanUpgradeResult>(`${this.baseUrl}/${tenantId}/upgrade?new_plan=${planKey}`, {});
|
||||
}
|
||||
|
||||
async canAddLocation(tenantId: string): Promise<{ can_add: boolean; reason?: string; current_count?: number; max_allowed?: number }> {
|
||||
return apiClient.get(`${this.baseUrl}/${tenantId}/can-add-location`);
|
||||
}
|
||||
|
||||
async canAddProduct(tenantId: string): Promise<{ can_add: boolean; reason?: string; current_count?: number; max_allowed?: number }> {
|
||||
return apiClient.get(`${this.baseUrl}/${tenantId}/can-add-product`);
|
||||
}
|
||||
|
||||
async canAddUser(tenantId: string): Promise<{ can_add: boolean; reason?: string; current_count?: number; max_allowed?: number }> {
|
||||
return apiClient.get(`${this.baseUrl}/${tenantId}/can-add-user`);
|
||||
}
|
||||
|
||||
async hasFeature(tenantId: string, featureName: string): Promise<{ has_feature: boolean; feature_value?: any; plan?: string; reason?: string }> {
|
||||
return apiClient.get(`${this.baseUrl}/${tenantId}/features/${featureName}`);
|
||||
}
|
||||
|
||||
formatPrice(amount: number): string {
|
||||
@@ -126,69 +114,6 @@ export class SubscriptionService {
|
||||
};
|
||||
return planInfo[planKey as keyof typeof planInfo] || { name: 'Desconocido', color: 'gray' };
|
||||
}
|
||||
|
||||
private getMockUsageSummary(): UsageSummary {
|
||||
return {
|
||||
plan: 'professional',
|
||||
status: 'active',
|
||||
monthly_price: 49.99,
|
||||
next_billing_date: new Date(Date.now() + 30 * 24 * 60 * 60 * 1000).toISOString(),
|
||||
usage: {
|
||||
users: {
|
||||
current: 3,
|
||||
limit: 10,
|
||||
unlimited: false,
|
||||
usage_percentage: 30
|
||||
},
|
||||
locations: {
|
||||
current: 1,
|
||||
limit: 3,
|
||||
unlimited: false,
|
||||
usage_percentage: 33
|
||||
},
|
||||
products: {
|
||||
current: 45,
|
||||
limit: -1,
|
||||
unlimited: true,
|
||||
usage_percentage: 0
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private getMockAvailablePlans(): AvailablePlans {
|
||||
return {
|
||||
plans: {
|
||||
starter: {
|
||||
name: 'Starter',
|
||||
description: 'Perfecto para panaderías pequeñas',
|
||||
monthly_price: 29.99,
|
||||
max_users: 3,
|
||||
max_locations: 1,
|
||||
max_products: 50,
|
||||
popular: false
|
||||
},
|
||||
professional: {
|
||||
name: 'Professional',
|
||||
description: 'Para panaderías en crecimiento',
|
||||
monthly_price: 49.99,
|
||||
max_users: 10,
|
||||
max_locations: 3,
|
||||
max_products: -1,
|
||||
popular: true
|
||||
},
|
||||
enterprise: {
|
||||
name: 'Enterprise',
|
||||
description: 'Para grandes operaciones',
|
||||
monthly_price: 99.99,
|
||||
max_users: -1,
|
||||
max_locations: -1,
|
||||
max_products: -1,
|
||||
contact_sales: true
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export const subscriptionService = new SubscriptionService();
|
||||
Reference in New Issue
Block a user