Files
TenerifeProp/public/js/api.js
TenerifeProp Dev c1867fe074 feat: implement complete backend with Bun + Hono + SQLite
- Create SQLite database schema with all tables
- Implement REST API endpoints for properties, leads, testimonials, FAQ, services
- Add seed data with sample properties, testimonials, FAQ
- Create Docker configuration for deployment
- Add i18n system for translations
- Add API client for frontend integration
- Create Technical Documentation (TZ.md)
- Add detailed README with deployment instructions

🚀 Project is now fully functional:
- API: http://localhost:8080/api/*
- Properties CRUD with filtering
- Lead management
- Settings, Testimonials, FAQ, Services APIs
- SQLite database with seed data
2026-04-04 22:16:06 +01:00

83 lines
2.2 KiB
JavaScript

// TenerifeProp - API Client
const API_BASE = '/api';
class API {
// Properties
static async getProperties(filters = {}) {
const params = new URLSearchParams(filters as any);
const response = await fetch(`${API_BASE}/properties?${params}`);
return response.json();
}
static async getProperty(slug, lang = 'es') {
const response = await fetch(`${API_BASE}/properties/${slug}?lang=${lang}`);
return response.json();
}
static async getFeaturedProperties(lang = 'es') {
const response = await fetch(`${API_BASE}/properties/featured?lang=${lang}`);
return response.json();
}
// Leads
static async createLead(data) {
const response = await fetch(`${API_BASE}/leads`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(data)
});
return response.json();
}
static async getLeads(filters = {}) {
const params = new URLSearchParams(filters as any);
const response = await fetch(`${API_BASE}/leads?${params}`);
return response.json();
}
// Content
static async getTestimonials(lang = 'es') {
const response = await fetch(`${API_BASE}/testimonials?lang=${lang}`);
return response.json();
}
static async getFAQ(lang = 'es') {
const response = await fetch(`${API_BASE}/faq?lang=${lang}`);
return response.json();
}
static async getServices(lang = 'es') {
const response = await fetch(`${API_BASE}/services?lang=${lang}`);
return response.json();
}
static async getSettings() {
const response = await fetch(`${API_BASE}/settings`);
return response.json();
}
// Analytics
static async trackEvent(type, data = {}) {
const sessionId = localStorage.getItem('session_id') || crypto.randomUUID();
localStorage.setItem('session_id', sessionId);
await fetch(`${API_BASE}/analytics/event`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
type,
session_id: sessionId,
...data
})
});
}
// Cities
static async getCities() {
const response = await fetch(`${API_BASE}/cities`);
return response.json();
}
}
// Export for use
window.API = API;