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,4 +1,4 @@
|
||||
<template>
|
||||
<template>
|
||||
<div class="admin-drivers">
|
||||
<div class="header">
|
||||
<button class="back-link" @click="$router.push('/admin')">← Volver al Panel</button>
|
||||
@ -37,7 +37,7 @@
|
||||
<div v-for="driver in activeDrivers" :key="driver.id" class="item-card" @click="viewDriverDetails(driver.id)">
|
||||
<div class="card-header">
|
||||
<div class="avatar">
|
||||
<img v-if="driver.driver_profile?.photo_url" :src="backendUrl + driver.driver_profile.photo_url" alt="Avatar">
|
||||
<img v-if="driver.driver_profiles?.photo_url" :src="getImageUrl(driver.driver_profiles.photo_url)" alt="Avatar">
|
||||
<span v-else class="material-icons">account_circle</span>
|
||||
</div>
|
||||
<div class="info">
|
||||
@ -135,11 +135,11 @@
|
||||
<div class="photo-viewer">
|
||||
<div v-if="selectedUser.driver_profile.photo_url">
|
||||
<label>Foto de Perfil:</label>
|
||||
<img :src="backendUrl + selectedUser.driver_profile.photo_url" alt="Perfil">
|
||||
<img :src="getImageUrl(selectedUser.driver_profile.photo_url)" alt="Perfil">
|
||||
</div>
|
||||
<div v-if="selectedUser.driver_profile.vehicle_photo_url">
|
||||
<label>Foto de Vehículo:</label>
|
||||
<img :src="backendUrl + selectedUser.driver_profile.vehicle_photo_url" alt="Vehículo">
|
||||
<img :src="getImageUrl(selectedUser.driver_profile.vehicle_photo_url)" alt="Vehículo">
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
@ -336,14 +336,13 @@
|
||||
import { ref, onMounted, reactive, computed } from 'vue'
|
||||
import { usersService } from '@/services/usersService'
|
||||
import { authService } from '@/services/authService'
|
||||
import { apiClient, API_URL } from '@/services/apiClient'
|
||||
import { supabase } from '@/supabase'
|
||||
|
||||
const activeTab = ref<'drivers' | 'taxis'>('drivers')
|
||||
const isLoading = ref(false)
|
||||
const activeDrivers = ref<any[]>([])
|
||||
const taxis = ref<any[]>([])
|
||||
const selectedUser = ref<any>(null)
|
||||
const backendUrl = API_URL
|
||||
|
||||
// Modal state
|
||||
const showModal = ref(false)
|
||||
@ -397,15 +396,13 @@ onMounted(() => {
|
||||
async function loadData() {
|
||||
isLoading.value = true
|
||||
try {
|
||||
// Load drivers
|
||||
const searchRes = await usersService.searchUsers('')
|
||||
activeDrivers.value = searchRes.filter((u: any) => u.role === 'driver')
|
||||
// Load drivers from Supabase
|
||||
const { data: drivers } = await supabase.from('users').select('*, driver_profiles(*)').eq('role', 'DRIVER')
|
||||
activeDrivers.value = drivers || []
|
||||
|
||||
// Load taxis
|
||||
const taxisRes = await apiClient.get('/api/taxis', {
|
||||
params: { is_active: undefined }
|
||||
})
|
||||
taxis.value = taxisRes.data
|
||||
// Load taxis from Supabase
|
||||
const { data: taxisData } = await supabase.from('taxis').select('*').order('owner_name')
|
||||
taxis.value = taxisData || []
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
} finally {
|
||||
@ -514,29 +511,23 @@ async function saveTaxi() {
|
||||
taxiError.value = ''
|
||||
|
||||
try {
|
||||
const formData = new FormData()
|
||||
formData.append('owner_name', taxiForm.owner_name)
|
||||
formData.append('phone_number', taxiForm.phone_number)
|
||||
formData.append('license_plate', taxiForm.license_plate)
|
||||
formData.append('corregimiento', taxiForm.corregimiento)
|
||||
formData.append('shift', taxiForm.shift)
|
||||
formData.append('rating', String(taxiForm.rating))
|
||||
formData.append('english_speaking', String(taxiForm.english_speaking))
|
||||
formData.append('is_active', String(taxiForm.is_active))
|
||||
|
||||
if (taxiForm.cooperative) formData.append('cooperative', taxiForm.cooperative)
|
||||
if (photoFile.value) formData.append('image', photoFile.value)
|
||||
|
||||
if (editingTaxi.value) {
|
||||
await apiClient.put(`/api/taxis/${editingTaxi.value.id}`, formData, {
|
||||
headers: { 'Content-Type': 'multipart/form-data' }
|
||||
})
|
||||
} else {
|
||||
await apiClient.post('/api/taxis', formData, {
|
||||
headers: { 'Content-Type': 'multipart/form-data' }
|
||||
})
|
||||
let image_url = editingTaxi.value?.image_url || null
|
||||
if (photoFile.value) {
|
||||
const ext = photoFile.value.name.split('.').pop()
|
||||
const filename = `taxis/${Date.now()}.${ext}`
|
||||
const { error: upErr } = await supabase.storage.from('uploads').upload(filename, photoFile.value)
|
||||
if (upErr) throw upErr
|
||||
const { data: urlData } = supabase.storage.from('uploads').getPublicUrl(filename)
|
||||
image_url = urlData.publicUrl
|
||||
}
|
||||
const payload = { ...taxiForm, image_url }
|
||||
if (editingTaxi.value) {
|
||||
const { error: e } = await supabase.from('taxis').update(payload).eq('id', editingTaxi.value.id)
|
||||
if (e) throw e
|
||||
} else {
|
||||
const { error: e } = await supabase.from('taxis').insert([payload])
|
||||
if (e) throw e
|
||||
}
|
||||
|
||||
closeModal()
|
||||
Object.assign(taxiForm, {
|
||||
owner_name: '', phone_number: '', license_plate: '', corregimiento: '',
|
||||
@ -544,7 +535,7 @@ async function saveTaxi() {
|
||||
})
|
||||
await loadData()
|
||||
} catch (e: any) {
|
||||
taxiError.value = e.response?.data?.detail || 'Error al guardar el taxi'
|
||||
taxiError.value = e.message || 'Error al guardar el taxi'
|
||||
console.error('Error saving taxi:', e)
|
||||
} finally {
|
||||
isSaving.value = false
|
||||
@ -553,13 +544,12 @@ async function saveTaxi() {
|
||||
|
||||
async function deleteTaxi(taxi: any) {
|
||||
if (!confirm(`¿Eliminar a ${taxi.owner_name} del directorio?`)) return
|
||||
|
||||
try {
|
||||
await apiClient.delete(`/api/taxis/${taxi.id}`)
|
||||
const { error: e } = await supabase.from('taxis').delete().eq('id', taxi.id)
|
||||
if (e) throw e
|
||||
await loadData()
|
||||
} catch (e) {
|
||||
alert('Error al eliminar el taxi')
|
||||
console.error('Error deleting taxi:', e)
|
||||
}
|
||||
}
|
||||
|
||||
@ -573,8 +563,9 @@ function getShiftLabel(shift: string) {
|
||||
}
|
||||
|
||||
function getImageUrl(path: string) {
|
||||
if (!path) return ''
|
||||
if (path.startsWith('http')) return path
|
||||
return `${API_URL}${path.startsWith('/') ? '' : '/'}${path}`
|
||||
return path
|
||||
}
|
||||
|
||||
function formatDate(dateStr: string) {
|
||||
@ -1161,3 +1152,5 @@ h1 {
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user