diff --git a/apps/hub-server/routes/router.ts b/apps/hub-server/routes/router.ts index 30bd83f7..09d3986b 100644 --- a/apps/hub-server/routes/router.ts +++ b/apps/hub-server/routes/router.ts @@ -8,38 +8,41 @@ const router: Router = Router(); router.use("/mail", mailRouter); router.use("/event", eventRouter); -router.get("/import", (req, res) => { - DATA.forEach(async (station) => { - try { - await prisma.station.create({ - data: { - aircraftRegistration: "D-H", - aircraft: station.aircraft, - aircraftSpeed: station.aircraftSpeed, - atcCallsign: station.atcCallsign, - bosCallsign: station.bosCallsign, - bosCallsignShort: station.bosCallsignShort, - bosRadioArea: station.bosRadioArea, - fir: station.fir, - operator: station.operator, - bosUse: "PRIMARY", - country: station.country as Country, - hasNvg: station.hasNvg, - hasRope: station.hasRope, - hasWinch: station.hasWinch, - is24h: station.is24h, - hideRangeRings: station.hideRangeRings, - locationState: station.locationState, - locationStateShort: station.locationStateShort, +router.get("/import", async (req, res) => { + await Promise.all( + DATA.map(async (station) => { + try { + return await prisma.station.create({ + data: { + aircraftRegistration: "D-H", + aircraft: station.aircraft, + aircraftSpeed: station.aircraftSpeed, + atcCallsign: station.atcCallsign, + bosCallsign: station.bosCallsign, + bosCallsignShort: station.bosCallsignShort, + bosRadioArea: station.bosRadioArea, + fir: station.fir, + operator: station.operator, + bosUse: "PRIMARY", + country: station.country as Country, + hasNvg: station.hasNvg, + hasRope: station.hasRope, + hasWinch: station.hasWinch, + is24h: station.is24h, + hideRangeRings: station.hideRangeRings, + locationState: station.locationState, + locationStateShort: station.locationStateShort, - latitude: station.latitude, - longitude: station.longitude, - }, - }); - } catch (error) { - console.error(`Error creating station ${station.aircraft}:`, error); - } - }); + latitude: station.latitude, + longitude: station.longitude, + }, + }); + } catch (error) { + console.error(`Error creating station ${station.aircraft}:`, error); + } + }), + ); + res.status(200).json({ message: "Import completed" }); }); export default router;