Files
edr-platform/apps/edr-passenger-web/backoffice/test-routes.html
2026-05-31 13:15:44 +03:00

101 lines
3.8 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<title>Test Routes API</title>
<style>
body { font-family: Arial, sans-serif; padding: 20px; }
button { padding: 10px 20px; margin: 10px 0; cursor: pointer; }
pre { background: #f4f4f4; padding: 15px; border-radius: 5px; overflow-x: auto; }
.route { border: 1px solid #ddd; padding: 10px; margin: 10px 0; border-radius: 5px; }
</style>
</head>
<body>
<h1>Routes API Test</h1>
<button onclick="fetchRoutes()">Fetch All Routes</button>
<button onclick="deleteRoute()">Delete ADD-DDW Route</button>
<div id="output"></div>
<script>
const API_URL = 'http://localhost:4000';
const TOKEN = localStorage.getItem('token') || 'YOUR_JWT_TOKEN_HERE';
async function fetchRoutes() {
try {
const response = await fetch(`${API_URL}/routes`, {
headers: {
'Authorization': `Bearer ${TOKEN}`
}
});
const data = await response.json();
console.log('Routes response:', data);
const output = document.getElementById('output');
output.innerHTML = '<h2>Routes Found:</h2>';
if (Array.isArray(data)) {
output.innerHTML += `<p>Total routes: ${data.length}</p>`;
data.forEach(route => {
output.innerHTML += `
<div class="route">
<strong>${route.code}</strong> - ${route.name}<br>
<small>ID: ${route.id}</small><br>
<small>Active: ${route.active}</small><br>
<small>Stops: ${route._count?.stops || route.stops?.length || 0}</small>
</div>
`;
});
} else {
output.innerHTML += '<pre>' + JSON.stringify(data, null, 2) + '</pre>';
}
} catch (error) {
document.getElementById('output').innerHTML =
'<p style="color: red;">Error: ' + error.message + '</p>';
console.error('Error:', error);
}
}
async function deleteRoute() {
const code = 'ADD-DDW';
try {
// First fetch to get the route ID
const listResponse = await fetch(`${API_URL}/routes`, {
headers: { 'Authorization': `Bearer ${TOKEN}` }
});
const routes = await listResponse.json();
const route = routes.find(r => r.code === code);
if (!route) {
alert('Route ADD-DDW not found');
return;
}
if (confirm(`Delete route ${route.code} - ${route.name}?`)) {
const response = await fetch(`${API_URL}/routes/${route.id}`, {
method: 'DELETE',
headers: {
'Authorization': `Bearer ${TOKEN}`
}
});
if (response.ok) {
alert('Route deleted successfully');
fetchRoutes();
} else {
const error = await response.json();
alert('Error: ' + JSON.stringify(error));
}
}
} catch (error) {
alert('Error: ' + error.message);
console.error('Error:', error);
}
}
// Auto-fetch on load
fetchRoutes();
</script>
</body>
</html>