chore: migrate AdminShuttles and old API endpoints from Axios/Render to Supabase client, remove Axios

This commit is contained in:
2026-02-26 14:51:03 -05:00
parent 30c3f092d8
commit 35a29fbb0f
9 changed files with 69 additions and 175 deletions

View File

@ -5,11 +5,9 @@ import { businessService } from '@/services/businessService'
import { couponsService } from '@/services/couponsService'
import { shuttlesService } from '@/services/shuttlesService'
import { useAuthStore } from '@/stores/auth'
import { SUPABASE_URL } from '@/supabase'
import { SUPABASE_URL, supabase } from '@/supabase'
import type { Coupon, Business, Shuttle } from '@/types'
const API_URL = import.meta.env.VITE_API_URL || 'http://localhost:8000';
const route = useRoute()
const authStore = useAuthStore()
@ -142,14 +140,13 @@ async function loadShuttles() {
// Shuttle Methods
async function toggleShuttleStatus(shuttle: Shuttle) {
try {
const token = localStorage.getItem('auth_token')
const response = await fetch(`${API_URL}/api/shuttles/${shuttle.id}/status?is_active=${!shuttle.is_active}`, {
method: 'PATCH',
headers: { 'Authorization': `Bearer ${token}` }
})
if (response.ok) {
await loadShuttles()
}
const { error } = await supabase
.from('shuttles')
.update({ is_active: !shuttle.is_active })
.eq('id', shuttle.id);
if (error) throw error;
await loadShuttles();
} catch (e) {
alert('Error al actualizar estado del shuttle')
}
@ -158,16 +155,13 @@ async function toggleShuttleStatus(shuttle: Shuttle) {
async function deleteShuttle(id: string) {
if (confirm('¿Estás seguro de eliminar este transporte turístico?')) {
try {
const token = localStorage.getItem('auth_token')
const response = await fetch(`${API_URL}/api/shuttles/${id}`, {
method: 'DELETE',
headers: { 'Authorization': `Bearer ${token}` }
})
if (response.ok) {
await loadShuttles()
} else {
alert('No se pudo eliminar el shuttle')
}
const { error } = await supabase
.from('shuttles')
.delete()
.eq('id', id);
if (error) throw error;
await loadShuttles();
} catch (e) {
alert('Error al eliminar shuttle')
}
@ -289,8 +283,7 @@ function openEditModal(coupon: Coupon) {
function getImageUrl(path: string | null | undefined) {
if (!path) return '/default-coupon.png'
if (path.startsWith('http')) return path
return `${API_URL}${path.startsWith('/') ? '' : '/'}${path}`
return path
}
async function saveCoupon() {