Skip to content

Commit

Permalink
fix: fix strava api call
Browse files Browse the repository at this point in the history
  • Loading branch information
rfoel committed Feb 1, 2021
1 parent f7ad0d9 commit 112d96a
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions pages/api/webhook.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import { NextApiRequest, NextApiResponse } from 'next'
import { NextApiRequestQuery } from 'next/dist/next-server/server/api-utils'
import { SubscriptionEvent } from 'strava'

import addActivity from '../../utils/addActivity'
import strava from '../../utils/strava'

const webhook = async (req: NextApiRequest, res: NextApiResponse) => {
try {
const { body, query } = req
const {
body,
query,
}: { body: SubscriptionEvent; query: NextApiRequestQuery } = req

if (query['hub.mode'] === 'subscribe') {
return res.json({
Expand All @@ -16,7 +21,9 @@ const webhook = async (req: NextApiRequest, res: NextApiResponse) => {
const { aspect_type, object_id, object_type } = body

if (aspect_type === 'create' && object_type === 'activity') {
const activity = await strava.activities.getActivityById(object_id)
const activity = await strava.activities.getActivityById({
id: object_id,
})

const run = await addActivity(activity)

Expand Down

0 comments on commit 112d96a

Please sign in to comment.