Skip to content

Commit

Permalink
add argument to getProgress (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
surz90 committed Aug 12, 2024
1 parent 8842cdd commit c496869
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
10 changes: 7 additions & 3 deletions src/progress/api.ts
Original file line number Diff line number Diff line change
@@ -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'

/**
Expand Down Expand Up @@ -90,11 +90,15 @@ export async function updateProgress(score: IScore, userId: string) {
}
}

export async function getProgress(): Promise<IProgress[] | undefined> {
export async function getProgress(
sortBy: ScoreKeys,
sortDirection: SortDirection,
limit: number = 10
): Promise<IProgress[] | undefined> {
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({
Expand Down
6 changes: 3 additions & 3 deletions src/progress/progress.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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)
}
5 changes: 5 additions & 0 deletions src/progress/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,8 @@ export type IProgress = IScore & {
data: Record<string, unknown>
updated_at: string
}

export enum SortDirection {
ASC = 'ASC',
DESC = 'DESC'
}

0 comments on commit c496869

Please sign in to comment.