Add new frontend - fix 19

This commit is contained in:
Urtzi Alfaro
2025-07-23 10:02:48 +02:00
parent 97e52dcfe5
commit b1639f5d9b
7 changed files with 168 additions and 175 deletions

View File

@@ -2,13 +2,46 @@
import { apiClient } from '../base/apiClient';
import { tokenManager } from '../auth/tokenManager';
import {
ApiResponse,
LoginRequest,
RegisterRequest,
TokenResponse,
UserProfile,
ApiResponse
} from '../types/api';
// Auth types
export interface LoginRequest {
email: string;
password: string;
}
export interface RegisterRequest {
email: string;
password: string;
full_name: string;
phone?: string;
language?: string;
}
export interface TokenResponse {
access_token: string;
refresh_token: string;
token_type: string;
expires_in: number;
}
export interface UserProfile {
id: string;
email: string;
full_name: string;
is_active: boolean;
is_verified: boolean;
tenant_id?: string;
role: string;
phone?: string;
language: string;
timezone: string;
created_at?: string;
last_login?: string;
}
export class AuthService {
/**
* Check if user is authenticated (has valid token)
@@ -27,7 +60,7 @@ export class AuthService {
* Get current user profile
*/
async getCurrentUser(): Promise<UserProfile> {
const response = await apiClient.get<ApiResponse<UserProfile>>('/users/me');
const response = await apiClient.get<UserProfile>('/users/me');
return response.data!;
}
@@ -141,11 +174,11 @@ export class AuthService {
* Update user profile
*/
async updateProfile(updates: Partial<UserProfile>): Promise<UserProfile> {
const response = await apiClient.put<ApiResponse<UserProfile>>(
const response = await apiClient.put<UserProfile>(
'/api/v1/users/me',
updates
);
return response.data!;
return response;
}
/**

View File

@@ -1,11 +1,7 @@
// src/api/services/DataService.ts
import { apiClient } from '../base/apiClient';
import {
ApiResponse,
SalesRecord,
CreateSalesRequest,
WeatherData,
TrafficData,
ApiResponse
} from '../types/api';
export interface DashboardStats {
@@ -33,6 +29,38 @@ export interface DataValidation {
duplicates: number;
}
// Data types
export interface WeatherData {
date: string;
temperature: number;
humidity: number;
precipitation: number;
wind_speed: number;
}
export interface TrafficData {
date: string;
traffic_volume: number;
pedestrian_count: number;
}
export interface SalesRecord {
id: string;
tenant_id: string;
product_name: string;
quantity_sold: number;
revenue: number;
date: string;
created_at: string;
}
export interface CreateSalesRequest {
product_name: string;
quantity_sold: number;
revenue: number;
date: string;
}
export class DataService {
/**
* Upload sales history file

View File

@@ -1,11 +1,30 @@
// src/api/services/ForecastingService.ts
import { apiClient } from '../base/apiClient';
import {
ApiResponse,
ForecastRecord,
ForecastRequest,
ApiResponse
} from '../types/api';
// Forecast types
export interface ForecastRecord {
id: string;
tenant_id: string;
product_name: string;
forecast_date: string;
predicted_quantity: number;
confidence_lower: number;
confidence_upper: number;
model_version: string;
created_at: string;
}
export interface ForecastRequest {
product_name?: string;
forecast_days?: number;
include_confidence?: boolean;
}
export interface SingleForecastRequest {
product_name: string;
forecast_date: string;

View File

@@ -2,8 +2,8 @@
import { apiClient } from '../base/apiClient';
import {
ApiResponse,
NotificationSettings,
} from '../types/api';
NotificationSettings
} from '@/api/services';
export interface NotificationCreate {
type: 'email' | 'whatsapp' | 'push';
@@ -101,6 +101,19 @@ export interface BulkNotificationStatus {
completed_at?: string;
}
// Notification types
export interface NotificationSettings {
email_enabled: boolean;
whatsapp_enabled: boolean;
training_notifications: boolean;
forecast_notifications: boolean;
alert_thresholds: {
low_stock_percentage: number;
high_demand_increase: number;
};
}
export class NotificationService {
/**
* Send single notification

View File

@@ -1,9 +1,8 @@
// src/api/services/TenantService.ts
import { apiClient } from '../base/apiClient';
import {
ApiResponse,
TenantInfo, // Assuming TenantInfo is equivalent to TenantResponse from backend
} from '../types/api';
ApiResponse
} from '@/api/services';
export interface TenantCreate {
name: string;
@@ -92,6 +91,20 @@ export interface TenantMemberResponse {
// Add any other fields expected from the backend's TenantMemberResponse
}
// Tenant types
export interface TenantInfo {
id: string;
name: string;
email: string;
phone: string;
address: string;
latitude: number;
longitude: number;
business_type: string;
is_active: boolean;
created_at: string;
}
export class TenantService {
/**
* Register a new bakery (tenant)

View File

@@ -1,12 +1,49 @@
// src/api/services/TrainingService.ts
import { apiClient } from '../base/apiClient';
import {
ApiResponse,
TrainingRequest,
TrainingJobStatus,
TrainedModel,
ApiResponse
} from '../types/api';
import {
ApiResponse
} from '@/api/services';
export interface TrainingJobStatus {
id: string;
tenant_id: string;
status: 'queued' | 'running' | 'completed' | 'failed' | 'cancelled';
progress: number;
current_step?: string;
started_at: string;
completed_at?: string;
duration_seconds?: number;
models_trained?: Record<string, any>;
metrics?: Record<string, any>;
error_message?: string;
}
export interface TrainingRequest {
force_retrain?: boolean;
products?: string[];
training_days?: number;
}
export interface TrainedModel {
id: string;
product_name: string;
model_type: string;
model_version: string;
mape?: number;
rmse?: number;
mae?: number;
r2_score?: number;
training_samples?: number;
features_used?: string[];
is_active: boolean;
created_at: string;
last_used_at?: string;
}
export interface TrainingJobProgress {
id: string;
status: 'queued' | 'running' | 'completed' | 'failed' | 'cancelled';

View File

@@ -18,153 +18,3 @@ export interface ApiError {
timestamp?: string;
}
// Auth types
export interface LoginRequest {
email: string;
password: string;
}
export interface RegisterRequest {
email: string;
password: string;
full_name: string;
phone?: string;
language?: string;
}
export interface TokenResponse {
access_token: string;
refresh_token: string;
token_type: string;
expires_in: number;
}
export interface UserProfile {
id: string;
email: string;
full_name: string;
is_active: boolean;
is_verified: boolean;
tenant_id?: string;
role: string;
phone?: string;
language: string;
timezone: string;
created_at?: string;
last_login?: string;
}
// Tenant types
export interface TenantInfo {
id: string;
name: string;
email: string;
phone: string;
address: string;
latitude: number;
longitude: number;
business_type: string;
is_active: boolean;
created_at: string;
}
// Sales types
export interface SalesRecord {
id: string;
tenant_id: string;
product_name: string;
quantity_sold: number;
revenue: number;
date: string;
created_at: string;
}
export interface CreateSalesRequest {
product_name: string;
quantity_sold: number;
revenue: number;
date: string;
}
// Training types
export interface TrainingJobStatus {
id: string;
tenant_id: string;
status: 'queued' | 'running' | 'completed' | 'failed' | 'cancelled';
progress: number;
current_step?: string;
started_at: string;
completed_at?: string;
duration_seconds?: number;
models_trained?: Record<string, any>;
metrics?: Record<string, any>;
error_message?: string;
}
export interface TrainingRequest {
force_retrain?: boolean;
products?: string[];
training_days?: number;
}
export interface TrainedModel {
id: string;
product_name: string;
model_type: string;
model_version: string;
mape?: number;
rmse?: number;
mae?: number;
r2_score?: number;
training_samples?: number;
features_used?: string[];
is_active: boolean;
created_at: string;
last_used_at?: string;
}
// Forecast types
export interface ForecastRecord {
id: string;
tenant_id: string;
product_name: string;
forecast_date: string;
predicted_quantity: number;
confidence_lower: number;
confidence_upper: number;
model_version: string;
created_at: string;
}
export interface ForecastRequest {
product_name?: string;
forecast_days?: number;
include_confidence?: boolean;
}
// Data types
export interface WeatherData {
date: string;
temperature: number;
humidity: number;
precipitation: number;
wind_speed: number;
}
export interface TrafficData {
date: string;
traffic_volume: number;
pedestrian_count: number;
}
// Notification types
export interface NotificationSettings {
email_enabled: boolean;
whatsapp_enabled: boolean;
training_notifications: boolean;
forecast_notifications: boolean;
alert_thresholds: {
low_stock_percentage: number;
high_demand_increase: number;
};
}