refactor: migrate fully to Supabase, remove Firebase/Render/Python backend
- DELETED: entire backend/ (Python/FastAPI — replaced by Supabase)
- DELETED: old/ directory (obsolete code)
- DELETED: render.yaml, inject_api.py, check_tags.py, PENDING_FOR_TOMORROW.md
- DELETED: frontend/src/firebaseConfig.ts (Firebase Auth replaced by Supabase Auth)
- DELETED: frontend/src/services/apiClient.ts (HTTP client for dead backend)
- MIGRATED services to Supabase native:
schedulesService, favoritesService, usersService,
telemetryService (stub), reportsService, analyticsService (stub)
- MIGRATED stores/favorites.ts to Supabase direct queries
- MIGRATED views: SplashScreen, AdminTaxis, AdminDrivers, StrategicAnalytics
- MIGRATED utils/imageUrl.ts to Supabase Storage URLs
- FIXED router/index.ts: guard now uses supabase.auth.getSession()
instead of old localStorage auth_token (fixes logout + map loading)
- FIXED AuthView.vue: removed aggressive watch({ immediate: true })
that caused wrong redirects on map route
- FIXED SplashScreen.vue: navigate() now reads Supabase session + role
- FIXED RLS: added INSERT policy on public.users for trigger
- CONFIRMED: admin@sibu.com assigned ADMIN role in Supabase
This commit is contained in:
@ -1,13 +1,18 @@
|
||||
/** Service for favorite-related API calls */
|
||||
import { apiClient } from './apiClient'
|
||||
import { supabase } from '@/supabase'
|
||||
import type { Favorite } from '@/types'
|
||||
|
||||
export const favoritesService = {
|
||||
/** Get all favorites for the current user */
|
||||
async getMyFavorites(itemType?: string): Promise<Favorite[]> {
|
||||
const params = itemType ? { item_type: itemType } : {}
|
||||
const response = await apiClient.get<Favorite[]>('/api/favorites', { params })
|
||||
return response.data
|
||||
const { data: userData } = await supabase.auth.getUser()
|
||||
if (!userData?.user) return []
|
||||
|
||||
let query = supabase.from('favorites').select('*').eq('user_id', userData.user.id)
|
||||
if (itemType) query = query.eq('item_type', itemType)
|
||||
const { data, error } = await query
|
||||
if (error) throw new Error(error.message)
|
||||
return data as Favorite[]
|
||||
},
|
||||
|
||||
/** Add a new favorite */
|
||||
@ -17,39 +22,53 @@ export const favoritesService = {
|
||||
itemName?: string,
|
||||
itemImage?: string
|
||||
): Promise<Favorite> {
|
||||
const response = await apiClient.post<Favorite>('/api/favorites', {
|
||||
const { data: userData } = await supabase.auth.getUser()
|
||||
if (!userData?.user) throw new Error('Not authenticated')
|
||||
|
||||
const { data, error } = await supabase.from('favorites').insert([{
|
||||
user_id: userData.user.id,
|
||||
item_type: itemType,
|
||||
item_id: itemId,
|
||||
item_name: itemName,
|
||||
item_image: itemImage
|
||||
})
|
||||
return response.data
|
||||
}]).select().single()
|
||||
if (error) throw new Error(error.message)
|
||||
return data as Favorite
|
||||
},
|
||||
|
||||
/** Remove a favorite by type and ID */
|
||||
async removeFavorite(itemType: string, itemId: string): Promise<void> {
|
||||
await apiClient.delete(`/api/favorites/${itemType}/${itemId}`)
|
||||
const { data: userData } = await supabase.auth.getUser()
|
||||
if (!userData?.user) throw new Error('Not authenticated')
|
||||
|
||||
const { error } = await supabase.from('favorites')
|
||||
.delete()
|
||||
.eq('user_id', userData.user.id)
|
||||
.eq('item_type', itemType)
|
||||
.eq('item_id', itemId)
|
||||
if (error) throw new Error(error.message)
|
||||
},
|
||||
|
||||
/** Remove a favorite by favorite ID (legacy support) */
|
||||
/** Remove a favorite by favorite ID */
|
||||
async removeFavoriteById(favoriteId: string): Promise<void> {
|
||||
// This requires finding the favorite first to get type and id
|
||||
const favorites = await this.getMyFavorites()
|
||||
const favorite = favorites.find(f => f.id === favoriteId)
|
||||
if (favorite) {
|
||||
await this.removeFavorite(favorite.item_type, favorite.item_id)
|
||||
}
|
||||
const { error } = await supabase.from('favorites').delete().eq('id', favoriteId)
|
||||
if (error) throw new Error(error.message)
|
||||
},
|
||||
|
||||
/** Check if an item is favorited */
|
||||
async checkFavorite(itemType: string, itemId: string): Promise<boolean> {
|
||||
try {
|
||||
const response = await apiClient.get<{ is_favorite: boolean }>(
|
||||
`/api/favorites/check/${itemType}/${itemId}`
|
||||
)
|
||||
return response.data.is_favorite
|
||||
} catch (error) {
|
||||
console.error('Error checking favorite:', error)
|
||||
const { data: userData } = await supabase.auth.getUser()
|
||||
if (!userData?.user) return false
|
||||
|
||||
const { data } = await supabase.from('favorites')
|
||||
.select('id')
|
||||
.eq('user_id', userData.user.id)
|
||||
.eq('item_type', itemType)
|
||||
.eq('item_id', itemId)
|
||||
.single()
|
||||
return !!data
|
||||
} catch {
|
||||
return false
|
||||
}
|
||||
},
|
||||
@ -62,7 +81,6 @@ export const favoritesService = {
|
||||
itemImage?: string
|
||||
): Promise<boolean> {
|
||||
const isFavorite = await this.checkFavorite(itemType, itemId)
|
||||
|
||||
if (isFavorite) {
|
||||
await this.removeFavorite(itemType, itemId)
|
||||
return false
|
||||
|
||||
Reference in New Issue
Block a user