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

@ -1,10 +1,7 @@
<script setup lang="ts">
import { ref } from 'vue';
import { useRouter } from 'vue-router';
import { SUPABASE_URL } from '@/supabase';
import axios from 'axios';
const API_URL = import.meta.env.VITE_API_URL || 'http://localhost:8000';
import { supabase } from '@/supabase';
const router = useRouter();
const isLoading = ref(false);
@ -53,33 +50,39 @@ async function saveShuttle() {
showMessage.value = { text: '', type: '' };
try {
const token = localStorage.getItem('auth_token');
const formData = new FormData();
// Añadimos campos obligatorios para el backend
formData.append('route_name', `${shuttleForm.value.origin} - ${shuttleForm.value.destination}`);
formData.append('origin', shuttleForm.value.origin);
formData.append('destination', shuttleForm.value.destination);
formData.append('vehicle_type', shuttleForm.value.vehicle_type);
formData.append('company_name', shuttleForm.value.company_name);
formData.append('price_per_person', String(shuttleForm.value.price_per_person));
formData.append('price_private_trip', String(shuttleForm.value.price_private_trip));
formData.append('estimated_duration', shuttleForm.value.estimated_duration);
formData.append('departure_times', shuttleForm.value.departure_times);
formData.append('contact_whatsapp', shuttleForm.value.contact_whatsapp);
formData.append('phone_number', shuttleForm.value.phone_number);
formData.append('english_speaking', String(shuttleForm.value.english_speaking));
let image_url = '';
if (selectedFile.value) {
formData.append('image', selectedFile.value);
const ext = selectedFile.value.name.split('.').pop();
const filename = `shuttles/${Date.now()}.${ext}`;
const { error: upErr } = await supabase.storage.from('uploads').upload(filename, selectedFile.value);
if (upErr) throw upErr;
const { data: urlData } = supabase.storage.from('uploads').getPublicUrl(filename);
image_url = urlData.publicUrl;
}
await axios.post(`${API_URL}/api/shuttles`, formData, {
headers: {
'Authorization': `Bearer ${token}`,
'Content-Type': 'multipart/form-data'
}
});
const payload = {
route_name: `${shuttleForm.value.origin} - ${shuttleForm.value.destination}`,
origin: shuttleForm.value.origin,
destination: shuttleForm.value.destination,
vehicle_type: shuttleForm.value.vehicle_type,
company_name: shuttleForm.value.company_name,
price_per_person: shuttleForm.value.price_per_person,
price_private_trip: shuttleForm.value.price_private_trip,
estimated_duration: shuttleForm.value.estimated_duration,
departure_times: shuttleForm.value.departure_times,
contact_whatsapp: shuttleForm.value.contact_whatsapp,
phone_number: shuttleForm.value.phone_number,
english_speaking: shuttleForm.value.english_speaking,
is_active: shuttleForm.value.is_active,
image_url: image_url || shuttleForm.value.image_url
};
const { error: insertError } = await supabase.from('shuttles').insert([payload]);
if (insertError) {
throw insertError;
}
showMessage.value = { text: '¡Viaje Turístico Desplegado!', type: 'success' };
setTimeout(() => router.push('/admin'), 2000);