Skip to content

feat: add admin reset action for active question answers with attendee answer clear#66

Merged
toddeTV merged 7 commits into
mainfrom
feat/answer-reset-flow
May 3, 2026
Merged

feat: add admin reset action for active question answers with attendee answer clear#66
toddeTV merged 7 commits into
mainfrom
feat/answer-reset-flow

Conversation

@toddeTV
Copy link
Copy Markdown
Owner

@toddeTV toddeTV commented May 3, 2026

Summary by CodeRabbit

  • New Features

    • Admins can now reset all submitted answers for the current active question via dedicated buttons on the questions and results pages.
    • Added real-time notification when answers are reset across connected clients.
  • Documentation

    • Updated API and WebSocket documentation for the new reset functionality.
  • Chores

    • Removed unused development dependency.

@toddeTV toddeTV self-assigned this May 3, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 3, 2026

📝 Walkthrough

Walkthrough

A new admin capability to reset answers for the active question is introduced. The feature includes a server API endpoint that clears answers and broadcasts a WebSocket event, client-side handlers to restore or clear stored answers, and admin UI controls in the questions and results pages with confirmation dialogs and localized labels.

Changes

Answer Reset Feature

Layer / File(s) Summary
Data Shape & Event Definition
docs/websocket.md
New server-to-client answers-reset event with { questionId: string } payload is documented for the default channel.
Storage Operation
server/utils/storage.ts
New clearAnswersForQuestion(questionId) function deletes all answers for a given question from storage.
API Endpoint
server/api/answers/reset.post.ts
New POST /api/answers/reset handler verifies admin access, clears answers via clearAnswersForQuestion(), broadcasts answers-reset and results-update WebSocket events, and returns { success: true, questionId }.
Client Socket Handling
app/composables/useQuizSocket.ts
Added clearStoredAnswer() and restoreStoredAnswer() helpers to manage sessionStorage and selectedAnswer. WebSocket listener updated to handle the new answers-reset event and restore stored answers on new-question.
Admin UI: Questions Page
app/pages/admin/questions.vue
Added isResettingAnswers reactive flag, resetAnswers() handler that posts to /api/answers/reset with confirmation, and a "Reset Answers" button with localized labels and error handling. Extended i18n (en/de/ja).
Admin UI: Results Page
app/pages/admin/results.vue
Added isResettingAnswers state, resetAnswers() handler that confirms, posts to /api/answers/reset, refreshes results on success, and alerts errors. Added "Reset Answers" button with localized labels. Extended i18n (en/de/ja).
API Documentation
docs/api.md
Documented the new POST /api/answers/reset endpoint, its empty request body, success response shape, and 404 error case when no active question exists.
Dependency Cleanup
package.json
Removed unused npm-run-all2 devDependency.

Sequence Diagram

sequenceDiagram
    actor Admin
    participant Questions Page
    participant API Endpoint
    participant Storage
    participant WebSocket
    participant Client Composable
    
    Admin->>Questions Page: Click "Reset Answers"
    Questions Page->>Questions Page: Show confirmation dialog
    Admin-->>Questions Page: Confirm
    Questions Page->>API Endpoint: POST /api/answers/reset
    API Endpoint->>Storage: clearAnswersForQuestion(questionId)
    Storage->>Storage: Delete all answers for question
    API Endpoint->>WebSocket: Broadcast answers-reset event
    WebSocket->>Client Composable: answers-reset message
    Client Composable->>Client Composable: clearStoredAnswer(questionId)
    API Endpoint->>WebSocket: Broadcast results-update event
    WebSocket->>Client Composable: results-update message
    API Endpoint-->>Questions Page: { success: true, questionId }
    Questions Page->>Questions Page: Reload questions
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • stage-flow-tools#49: Modifies client answer-restoration in app/composables/useQuizSocket.ts for handling stored answer recovery and clearing on question changes, directly overlapping with this PR's client socket refactoring.
  • stage-flow-tools#48: Updates server/utils/storage.ts to refactor storage operations and adds answer-reset related APIs; both PRs modify the same storage utility layer.
  • stage-flow-tools#20: Modifies both app/composables/useQuizSocket.ts and server/utils/storage.ts, with overlapping changes to socket event handling and server storage operations.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 40.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main feature: adding an admin reset action to clear answers for the active question, which is reflected across all changed files (API endpoint, WebSocket events, UI components, and storage utilities).
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Review rate limit: 3/5 reviews remaining, refill in 12 minutes and 26 seconds.

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (3)
app/pages/admin/questions.vue (1)

270-295: ⚡ Quick win

Add a brief JSDoc for resetAnswers().

The function is good; it just needs a short doc comment for consistency with repo standards.

As per coding guidelines, "Brief JSDoc on all functions."

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@app/pages/admin/questions.vue` around lines 270 - 295, Add a brief JSDoc
block above the async function resetAnswers() that summarizes its purpose
(prompts the user, posts to /api/answers/reset, reloads questions, and handles
errors), documents that it is asynchronous and returns a Promise<void>, and
notes side effects (uses window.confirm, updates isResettingAnswers.value, calls
loadQuestions(), and may show an alert). Keep the comment concise (one- or
two-line summary plus `@returns` Promise<void> and an optional `@throws/notes` line
about error handling).
app/composables/useQuizSocket.ts (1)

12-32: ⚡ Quick win

Add brief JSDoc for the new helper functions.

Both newly introduced helpers are clear, but they should include short JSDoc to match repo standards.

Suggested update
+/** Clear in-memory and session-stored answer for a question. */
 function clearStoredAnswer(questionId: string) {
   selectedAnswer.value = null

   if (import.meta.client) {
     sessionStorage.removeItem(`answer-${questionId}`)
   }
 }

+/** Restore a previously stored answer for a question from session storage. */
 function restoreStoredAnswer(questionId: string) {
   if (!import.meta.client) {
     selectedAnswer.value = null
     return
   }

As per coding guidelines, "Brief JSDoc on all functions."

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@app/composables/useQuizSocket.ts` around lines 12 - 32, Add brief JSDoc
comments for the two helper functions clearStoredAnswer and restoreStoredAnswer:
above clearStoredAnswer describe that it clears the in-memory selectedAnswer and
removes the sessionStorage key for the provided questionId (include `@param`
{string} questionId), and above restoreStoredAnswer describe that it reads the
sessionStorage key for questionId, parses it to an integer, validates
non-negative integer and sets selectedAnswer accordingly or null (include `@param`
{string} questionId and `@returns` {void} or note no return). Also mention the
client-only behavior (checks import.meta.client) in the JSDoc to clarify server
vs client side effects.
app/pages/admin/results.vue (1)

208-230: ⚡ Quick win

Add a brief JSDoc for resetAnswers().

Please add a short doc comment above this new function to align with project conventions.

As per coding guidelines, "Brief JSDoc on all functions."

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@app/pages/admin/results.vue` around lines 208 - 230, Add a brief JSDoc block
immediately above the async function resetAnswers() describing its purpose
(resets all answers after user confirmation), noting it is asynchronous and
returns a Promise<void>, and listing side effects such as updating
isResettingAnswers.value, calling the /api/answers/reset via $fetch, invoking
refreshResults(), and handling errors (logged via logger_error); keep it short
(one to three lines) and follow the project's JSDoc style.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@app/composables/useQuizSocket.ts`:
- Around line 12-32: Add brief JSDoc comments for the two helper functions
clearStoredAnswer and restoreStoredAnswer: above clearStoredAnswer describe that
it clears the in-memory selectedAnswer and removes the sessionStorage key for
the provided questionId (include `@param` {string} questionId), and above
restoreStoredAnswer describe that it reads the sessionStorage key for
questionId, parses it to an integer, validates non-negative integer and sets
selectedAnswer accordingly or null (include `@param` {string} questionId and
`@returns` {void} or note no return). Also mention the client-only behavior
(checks import.meta.client) in the JSDoc to clarify server vs client side
effects.

In `@app/pages/admin/questions.vue`:
- Around line 270-295: Add a brief JSDoc block above the async function
resetAnswers() that summarizes its purpose (prompts the user, posts to
/api/answers/reset, reloads questions, and handles errors), documents that it is
asynchronous and returns a Promise<void>, and notes side effects (uses
window.confirm, updates isResettingAnswers.value, calls loadQuestions(), and may
show an alert). Keep the comment concise (one- or two-line summary plus `@returns`
Promise<void> and an optional `@throws/notes` line about error handling).

In `@app/pages/admin/results.vue`:
- Around line 208-230: Add a brief JSDoc block immediately above the async
function resetAnswers() describing its purpose (resets all answers after user
confirmation), noting it is asynchronous and returns a Promise<void>, and
listing side effects such as updating isResettingAnswers.value, calling the
/api/answers/reset via $fetch, invoking refreshResults(), and handling errors
(logged via logger_error); keep it short (one to three lines) and follow the
project's JSDoc style.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: 7fa5572e-6e84-42de-ad63-5974cc04a421

📥 Commits

Reviewing files that changed from the base of the PR and between 177e026 and 524b777.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml, !pnpm-lock.yaml
📒 Files selected for processing (8)
  • app/composables/useQuizSocket.ts
  • app/pages/admin/questions.vue
  • app/pages/admin/results.vue
  • docs/api.md
  • docs/websocket.md
  • package.json
  • server/api/answers/reset.post.ts
  • server/utils/storage.ts
💤 Files with no reviewable changes (1)
  • package.json

@toddeTV toddeTV merged commit 8d771a3 into main May 3, 2026
5 checks passed
@toddeTV toddeTV deleted the feat/answer-reset-flow branch May 3, 2026 23:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant