Skip to content

User Endorsed Count#517

Merged
kjassani merged 10 commits intomainfrom
karim/endorse-count
Apr 9, 2026
Merged

User Endorsed Count#517
kjassani merged 10 commits intomainfrom
karim/endorse-count

Conversation

@kjassani
Copy link
Copy Markdown
Collaborator

@kjassani kjassani commented Apr 8, 2026

Description

Implements per-user endorsed comment count tracking using a query-based approach rather than a stored counter column, avoiding data synchronization risks.

Behaviour: When a staff member endorses a student's async question comment, that endorsement is recorded on the comment itself (endorsedById). The new getEndorsedCountByCourse method can then be called at any time to get an up-to-date count of how many endorsed comments each student has in a course . This count is not yet surfaced in any API response or UI, but it is ready to be wired into future badge/achievement logic that rewards students for contributing high-quality answers.

Changes

New Query Method (AsyncQuestionService)

  • Added getEndorsedCountByCourse(courseId)
    • Runs a single aggregate query: COUNT(*) GROUP BY creatorId over endorsed comments for a course
    • Returns Map<userId, count>
    • No stored state → eliminates risk of data going out of sync

Refactored Endorse & Delete Comment Endpoints (asyncQuestionController)

  • Replaced @Res() manual response handling with NestJS exceptions:
  • Improves consistency with the rest of the codebase and simplifies control flow

Reverted Stored Column Approach

  • Removed endorsedCommentCount column from UserCourseModel
  • Removed associated migration file

Closes #506

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update
  • This requires a run of yarn install
  • This change requires an addition/change to the production .env variables. These changes are below:
  • This change requires developers to add new .env variables. The file and variables needed are below:
  • This change requires a database query to update old data on production. This query is below:

How Has This Been Tested?

Added 4 integration tests for getEndorsedCountByCourse covering:

  • No endorsed comments → empty map
  • Single endorsed comment → correct count
  • Multiple endorsed comments for different users
  • Correct filtering by course

Checklist:

  • I have performed a code review of my own code (under the "Files Changed" tab on github) to ensure nothing is committed that shouldn't be (e.g. leftover console.logs, leftover unused logic, or anything else that was accidentally committed)
  • I have commented my code where needed
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • I have checked that new and existing tests pass locally with my changes
  • Any work that this PR is dependent on has been merged into the main branch
  • Any UI changes have been checked to work on desktop, tablet, and mobile

@kjassani kjassani self-assigned this Apr 8, 2026
@kjassani kjassani force-pushed the karim/endorse-count branch from d81442b to d09667b Compare April 9, 2026 19:43
@kjassani kjassani marked this pull request as ready for review April 9, 2026 20:04
@kjassani kjassani requested a review from AdamFipke April 9, 2026 20:04
Copy link
Copy Markdown
Collaborator

@AdamFipke AdamFipke left a comment

Choose a reason for hiding this comment

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

looks good!

@kjassani kjassani merged commit 4f93f2c into main Apr 9, 2026
2 checks passed
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.

Track per-user endorsed comment count

2 participants