Skip to content

Commit

Permalink
added business check and multiple trips
Browse files Browse the repository at this point in the history
  • Loading branch information
cankurttekin committed Sep 25, 2024
1 parent b91964a commit 20f40f2
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function postRequest(url, body) {

async function loadStations() {
if (Object.keys(stationsData).length === 0) {
document.getElementById("status").innerHTML = "Fetching stations... " + "<br />";
document.getElementById("status").innerHTML = "Fetching stations..." + "<br />";
const url = api_url + stations_endpoint;
const body = {
"kanalKodu": "3",
Expand All @@ -47,7 +47,7 @@ async function loadStations() {
return acc;
}, {});
console.log('Stations are updated.');
document.getElementById("status").innerHTML = "Stations loaded. " + "<br />";
document.getElementById("status").innerHTML = "Stations loaded." + "<br />";
} else {
console.error('Failed to fetch stations: ', response);
}
Expand Down Expand Up @@ -129,10 +129,31 @@ function checkTrip(trip) {
business_seat_count += vagon.kalanSayi;
}
});

const tripDateTime = new Date(trip.binisTarih);
const depart = tripDateTime.toTimeString().substring(0, 5);
const arrive = new Date(trip.inisTarih).toTimeString().substring(0, 5);
const tripTime = depart + " ———> " + arrive;
const tripDate = tripDateTime.toDateString().substring(0, 10);

if (seatType === "economy" && economy_seat_count > 0) {
document.getElementById("status").innerHTML = `Seats Available for: ${trip.binisTarih} 💺:${economy_seat_count} ♿:${disabled_seat_count} 🛄:${business_seat_count} <br/>`;
document.getElementById("status").innerHTML
+= `<br/><span style="color:Tomato;"><b> »»» Economy seats available for:</b></span><br/>
${tripDate}, ${tripTime}:<br/>
&emsp;&emsp;💺 <b>Economy: ${economy_seat_count}</b><br/>
&emsp;&emsp;🛄 Business: ${business_seat_count} <br/>
&emsp;&emsp;♿ Disabled: ${disabled_seat_count}<br/>`;
found = true;
audio.play();
} else if (seatType === "business" && business_seat_count > 0) {
document.getElementById("status").innerHTML
+= `<br/><span style="color:Tomato;"><b>Business seats available for:</b></span><br/>
${tripDate}, ${tripTime}:<br/>
&emsp;&emsp;🛄 <b>Business: ${business_seat_count}</b><br/>
&emsp;&emsp;💺 Economy: ${economy_seat_count}<br/>
&emsp;&emsp;♿ Disabled: ${disabled_seat_count}<br/> `;
found = true;
audio.play();
audio.play();
}
}

Expand Down

0 comments on commit 20f40f2

Please sign in to comment.