-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(fe): don't calculate contest score when contest is upcoming (#2082)
* fix(fe): don't calculate contest score when contest is upcoming * refactor(fe): use safeFetcher on calculateContestScore * fix(fe): use default value when input,output description doesn't exist * fix(fe): show default value when input description or output description is null
- Loading branch information
Showing
3 changed files
with
35 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,32 @@ | ||
import { fetcherWithAuth } from '@/lib/utils' | ||
import { safeFetcherWithAuth } from '@/lib/utils' | ||
import type { ContestProblem } from '@/types/type' | ||
|
||
interface ContestProblemsApiRes { | ||
data: ContestProblem[] | ||
} | ||
|
||
const calculateContestScore = async ({ contestId }: { contestId: string }) => { | ||
const contestProblems: ContestProblemsApiRes = await fetcherWithAuth | ||
.get(`contest/${contestId}/problem`) | ||
.json() | ||
try { | ||
const contestProblems: ContestProblemsApiRes = await safeFetcherWithAuth | ||
.get(`contest/${contestId}/problem`) | ||
.json() | ||
|
||
const { totalScore, totalMaxScore } = contestProblems.data.reduce( | ||
(acc, curr) => { | ||
const score = curr.score ? parseInt(curr.score, 10) : 0 | ||
const maxScore = curr.maxScore || 0 | ||
const { totalScore, totalMaxScore } = contestProblems.data.reduce( | ||
(acc, curr) => { | ||
const score = curr.score ? parseInt(curr.score, 10) : 0 | ||
const maxScore = curr.maxScore || 0 | ||
|
||
acc.totalScore += score | ||
acc.totalMaxScore += maxScore | ||
acc.totalScore += score | ||
acc.totalMaxScore += maxScore | ||
|
||
return acc | ||
}, | ||
{ totalScore: 0, totalMaxScore: 0 } | ||
) | ||
return [totalScore, totalMaxScore] | ||
return acc | ||
}, | ||
{ totalScore: 0, totalMaxScore: 0 } | ||
) | ||
return [totalScore, totalMaxScore] | ||
} catch (error) { | ||
return [0, 0] | ||
} | ||
} | ||
|
||
export { calculateContestScore } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters