Skip to content

Commit

Permalink
fix: prevent invalid problem session
Browse files Browse the repository at this point in the history
  • Loading branch information
exKAZUu committed Sep 26, 2024
1 parent ef857c2 commit 543e9e7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,16 @@ export const ProblemBody: React.FC<Props> = (props) => {
const response = await fetchIncorrectSubmissionsCount();
const incorrectCount = (response.data ?? 0) + 1;
void props.createSubmissionUpdatingProblemSession(false, false);
if (incorrectCount === MAX_CHALLENGE_COUNT) {
void props.updateProblemSession('step', 1);
if (incorrectCount < MAX_CHALLENGE_COUNT) {
openAlertDialog(
'不正解',
`不正解です。${MAX_CHALLENGE_COUNT}回間違えたので、ステップ実行モードに移ります。ステップごとに問題を解いてください。`
`不正解です。あと${MAX_CHALLENGE_COUNT - incorrectCount}回間違えたら、ステップ実行モードに移ります。一発正解を目指しましょう!`
);
} else {
void props.updateProblemSession('step', 1);
openAlertDialog(
'不正解',
`不正解です。あと${MAX_CHALLENGE_COUNT - incorrectCount}回間違えたら、ステップ実行モードに移ります。一発正解を目指しましょう!`
`不正解です。${MAX_CHALLENGE_COUNT}回間違えたので、ステップ実行モードに移ります。ステップごとに問題を解いてください。`
);
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/infrastructures/trpcBackend/routers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ export const backendRouter = router({
})
)
.mutation(async ({ input: { id, incrementalElapsedMilliseconds, ...data } }) => {
if (data.problemType === 'step' && data.traceItemIndex === 0) {
throw new TRPCError({ code: 'BAD_REQUEST' });
}

const problemSession = await prisma.problemSession.update({
where: { id },
data: {
Expand Down

0 comments on commit 543e9e7

Please sign in to comment.