diff --git a/src/progress/api.ts b/src/progress/api.ts index 6f0ff4c..5c70cc9 100644 --- a/src/progress/api.ts +++ b/src/progress/api.ts @@ -1,6 +1,6 @@ import { signedFetch } from '~system/SignedFetch' import { GAME_SERVER } from '../config' -import { IChallenge, IProgress, IScore } from './types' +import { IChallenge, IProgress, IScore, ScoreKeys, SortDirection } from './types' import { getSDK } from '../sdk' /** @@ -90,11 +90,15 @@ export async function updateProgress(score: IScore, userId: string) { } } -export async function getProgress(): Promise { +export async function getProgress( + sortBy: ScoreKeys, + sortDirection: SortDirection, + limit: number = 10 +): Promise { const { config } = getSDK() // {{host}}/api/games/:id/progress?sort=level&limit=10&direction=DESC - const url = `${GAME_SERVER}/api/games/${config.gameId}/progress?sort=level&limit=10&direction=DESC` + const url = `${GAME_SERVER}/api/games/${config.gameId}/progress?sort=${sortBy}&limit=${limit}&direction=${sortDirection}` console.log('get progress url:', url) try { const response = await signedFetch({ diff --git a/src/progress/progress.ts b/src/progress/progress.ts index 6ec33f6..8992f24 100644 --- a/src/progress/progress.ts +++ b/src/progress/progress.ts @@ -1,4 +1,4 @@ -import { IScore } from './types' +import { IScore, ScoreKeys, SortDirection } from './types' import { getSDK } from '../sdk' import { checkIfChallengeComplete } from '.' import * as api from './api' @@ -13,6 +13,6 @@ export async function upsertProgress(score: IScore) { } } -export async function getProgress() { - return api.getProgress() +export async function getProgress(sortBy: ScoreKeys, sortDirection: SortDirection, limit?: number) { + return api.getProgress(sortBy, sortDirection, limit) } diff --git a/src/progress/types.ts b/src/progress/types.ts index 50b485a..12d91a9 100644 --- a/src/progress/types.ts +++ b/src/progress/types.ts @@ -46,3 +46,8 @@ export type IProgress = IScore & { data: Record updated_at: string } + +export enum SortDirection { + ASC = 'ASC', + DESC = 'DESC' +}