Skip to content

Commit

Permalink
Added all parameters to Challenges api
Browse files Browse the repository at this point in the history
Fixes helium#315 by adding `min_time`, `max_time` and `limit` parameters to the Challenges api call.
  • Loading branch information
markdegrootnl authored Jul 29, 2022
1 parent 20d7cf8 commit 3a5b05e
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion packages/http/src/resources/Challenges.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@ import Account from '../models/Account'
import Hotspot from '../models/Hotspot'
import Sums, { SumsType } from './Sums'

export type NaturalDate = string // in the format "-${number} ${Bucket}" eg "-1 day"

interface ListParams {
cursor?: string
minTime?: Date | NaturalDate
maxTime?: Date | NaturalDate
limit?: number
}

type Context = Account | Hotspot
Expand All @@ -30,7 +35,12 @@ export default class Challenges {
const hotspot = this.context as Hotspot
url = `/hotspots/${hotspot.address}/challenges`
}
const response = await this.client.get(url, { cursor: params.cursor })
const response = await this.client.get(url, {
cursor: params.cursor,
min_time: params.minTime instanceof Date ? params.minTime?.toISOString() : params.minTime,
max_time: params.maxTime instanceof Date ? params.maxTime?.toISOString() : params.maxTime,
limit: params.limit,
})
const { data: { data: challenges, cursor } } = response
const data = challenges.map((d: HTTPChallengeObject) => new Challenge(d))
return new ResourceList(data, this.list.bind(this), cursor)
Expand Down

0 comments on commit 3a5b05e

Please sign in to comment.