diff --git a/CHANGELOG.md b/CHANGELOG.md index 8908963..a8a3e33 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,13 @@ # Changelog +### Version 1.1.0 + +#### bugfix +* PR [#25](https://github.com/petercort/FBF-Buddy/pull/25) - updating the initial sync and healthchecks + + + ### Version 1.0.2 #### bugfix diff --git a/app.version b/app.version index 21e8796..9084fa2 100644 --- a/app.version +++ b/app.version @@ -1 +1 @@ -1.0.3 +1.1.0 diff --git a/package.json b/package.json index 661ab11..83c7a36 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "fbf-event-buddy", "private": true, - "version": "1.0.2", + "version": "1.1.0", "description": "Cycling event app for Discord", "main": "app.js", "engines": { diff --git a/src/commands.js b/src/commands.js index 3503b9f..b524854 100644 --- a/src/commands.js +++ b/src/commands.js @@ -46,17 +46,12 @@ const rest = new REST().setToken(discordToken); (async () => { try { console.log(`Started refreshing ${commands.length} application (/) commands.`); - // The put method is used to fully refresh all commands in the guild with the current set - const data = await rest.put( - Routes.applicationGuildCommands(appId, guildId), - { body: commands }, - ); - await rest.put( + const data = await rest.put( Routes.applicationCommands(appId), { body: commands }, ); - console.log(`Successfully reloaded ${data.length} application (/) commands.`); + console.log(`Successfully reloaded ${data.length} application (/) commands.`); } catch (error) { // And of course, make sure you catch and log any errors! console.error(error); diff --git a/src/commands/utility/archive_event.js b/src/commands/events/archive_event.js similarity index 100% rename from src/commands/utility/archive_event.js rename to src/commands/events/archive_event.js diff --git a/src/commands/utility/create_event.js b/src/commands/events/create_event.js similarity index 100% rename from src/commands/utility/create_event.js rename to src/commands/events/create_event.js diff --git a/src/commands/utility/get_all_events.js b/src/commands/events/get_all_events.js similarity index 100% rename from src/commands/utility/get_all_events.js rename to src/commands/events/get_all_events.js diff --git a/src/commands/utility/get_event.js b/src/commands/events/get_event.js similarity index 100% rename from src/commands/utility/get_event.js rename to src/commands/events/get_event.js diff --git a/src/commands/utility/update_event.js b/src/commands/events/update_event.js similarity index 100% rename from src/commands/utility/update_event.js rename to src/commands/events/update_event.js diff --git a/src/commands/utility/connect_strava.js b/src/commands/strava/connect_strava.js similarity index 100% rename from src/commands/utility/connect_strava.js rename to src/commands/strava/connect_strava.js diff --git a/src/commands/utility/get_all_bikes.js b/src/commands/strava/get_all_bikes.js similarity index 100% rename from src/commands/utility/get_all_bikes.js rename to src/commands/strava/get_all_bikes.js diff --git a/src/commands/utility/get_bike_by_name.js b/src/commands/strava/get_bike_by_name.js similarity index 100% rename from src/commands/utility/get_bike_by_name.js rename to src/commands/strava/get_bike_by_name.js diff --git a/src/commands/utility/get_last_ride.js b/src/commands/strava/get_last_ride.js similarity index 100% rename from src/commands/utility/get_last_ride.js rename to src/commands/strava/get_last_ride.js diff --git a/src/commands/utility/i_waxed_my_chain.js b/src/commands/strava/i_waxed_my_chain.js similarity index 100% rename from src/commands/utility/i_waxed_my_chain.js rename to src/commands/strava/i_waxed_my_chain.js diff --git a/src/commands/utility/sync_bikes.js b/src/commands/strava/sync_bikes.js similarity index 100% rename from src/commands/utility/sync_bikes.js rename to src/commands/strava/sync_bikes.js diff --git a/src/strava_webhook.js b/src/strava_webhook.js index aeb3ea9..ae00cfa 100644 --- a/src/strava_webhook.js +++ b/src/strava_webhook.js @@ -7,9 +7,22 @@ const fs = require('node:fs'); const { firstTimeAuth, getStravaAuthentication } = require('./shared_library/strava_authentication.js'); const app = express(); app.use(express.json()); -const discordToken = fs.readFileSync("/mnt/secrets-store/discordToken", 'utf8'); +require('dotenv').config() +let discordToken; + +if (process.env.NODE_ENV === 'production') { + discordToken = fs.readFileSync("/mnt/secrets-store/discordToken", 'utf8'); +} else { + discordToken = process.env.discordToken; +} + client.login(discordToken); +app.get('/', (req, res) => { + // send a 200 response to the root path + res.sendStatus(200); +}); + app.post('/webhook', async (req, res) => { console.log("webhook event received!", req.body); // get the object_id and owner id @@ -107,13 +120,16 @@ async function setupBikes(athleteId, userId, strava_access_token) { // get the athlete page // Fetch details for each bike from Strava's /gear endpoint and update the database for (const bike of athleteResponse.data.bikes) { + const bikeData = await axios.get(`https://www.strava.com/api/v3/gear/${bike.id}`, { + headers: { Authorization: `Bearer ${strava_access_token}` } + }); // Update the database with the bike details await BikesTable.upsert({ bikeId: bike.id, userId: userId, name: bike.name, - brand: bike.brand_name, - model: bike.model_name, + brand: bikeData.data.brand_name, + model: bikeData.data.model_name, distance: bike.distance }); }