From 3a5b05e838720dba87c13df727d11b077144eb34 Mon Sep 17 00:00:00 2001 From: Mark de Groot Date: Fri, 29 Jul 2022 20:52:17 +0200 Subject: [PATCH] Added all parameters to Challenges api Fixes #315 by adding `min_time`, `max_time` and `limit` parameters to the Challenges api call. --- packages/http/src/resources/Challenges.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/http/src/resources/Challenges.ts b/packages/http/src/resources/Challenges.ts index 7795232d..bc34212b 100644 --- a/packages/http/src/resources/Challenges.ts +++ b/packages/http/src/resources/Challenges.ts @@ -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 @@ -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)