-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
60068be
commit 90d44bb
Showing
6 changed files
with
56 additions
and
48 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import axios from "axios"; | ||
import { TrainingStation } from "../../models/TrainingStation"; | ||
|
||
type DataHubStations = { | ||
logon: string; | ||
frequency: string; | ||
abbreviation: string; | ||
description: string; | ||
gcap_status?: string; | ||
gcap_training_airport?: boolean; | ||
s1_twr?: boolean; | ||
}; | ||
|
||
export async function updateTrainingStations() { | ||
const res = await axios.get("https://raw.githubusercontent.com/VATGER-Nav/datahub/main/data.json"); | ||
|
||
const stations = res.data as DataHubStations[]; | ||
|
||
for (const station of stations) { | ||
if (station.logon.length === 0 || station.frequency.length === 0) continue; | ||
|
||
const gcap_class_str = station.gcap_status ?? "0"; | ||
const gcap_class_nr = gcap_class_str === "0" || gcap_class_str === "1" ? parseInt(gcap_class_str, 10) : 2; | ||
|
||
const stationData = { | ||
callsign: station.logon, | ||
frequency: Number(station.frequency), | ||
gcap_class: gcap_class_nr, | ||
gcap_class_group: gcap_class_str, | ||
gcap_training_airport: station.gcap_training_airport ?? false, | ||
s1_twr: station.s1_twr ?? false, | ||
}; | ||
|
||
const dbStation = await TrainingStation.findOne({ where: { callsign: station.logon } }); | ||
if (dbStation == null) { | ||
await TrainingStation.create(stationData); | ||
continue; | ||
} | ||
|
||
await dbStation.update(stationData); | ||
} | ||
} |