Imagine a fusion of ‘Eskom se Push’ and ‘X’. The Republic allows users to raise concerns and spread awareness about government services through incident reports, with cool data visualizations providing a dynamic overview of public sentiment on service delivery.
This PR introduces a comprehensive gamification system, including a points mechanism, location-based leaderboards, and user suspension/blocking features. It also includes significant updates to the User model and related services.
Major Changes
Points System
Implemented PointsRepository for managing user scores
Added methods for updating user scores and logging point transactions
Integrated point awarding/deduction in relevant services (Comments, Issues, etc.)
Leaderboard Functionality
Implemented location-based leaderboards in PointsRepository
Added getLeaderboard and getUserPosition methods with location filtering
Created PointsService to handle leaderboard and user position logic
User Model and Repository Updates
Added user_score, location_id, and location properties to User interface
Updated UserRepository to handle new user properties
Implemented methods for updating user locations
Suspension and Blocking Features
Added suspendUserFromResolving method to temporarily restrict user actions
Implemented blockUser method for permanent restrictions
Service Updates
Updated IssueService, CommentService, and UserService to integrate with new points system
Modified services to handle anonymous users consistently
Implementation Details
Points Awarding Rules
+100 points for the first issue resolved, +50 points thereafter
+50 points for first issue created, +20 points thereafter
+10 points for leaving a comment on an open issue
+5 points for reacting to an issue
-75 points for falsely resolving someone else's issue
-200 points for breaking community guidelines
User Restrictions
Users are suspended from resolving issues for 24 hours after an incorrect resolution
Users with scores below -150 have their accounts blocked
Leaderboard and User Position
Leaderboards show top 10 users based on score and location
User positions are calculated considering location filters (province, city, suburb)
Nationwide leaderboard is provided when no location filter is specified
Testing
Updated existing tests in commentService.test.ts, issueService.test.ts, and userService.test.ts
Added new tests for PointsRepository and PointsService
Implemented integration tests for the points system and leaderboard functionality
API Changes
New endpoint: POST /api/points/leaderboard for fetching leaderboards
How to Use the Leaderboard Endpoint
This endpoint retrieves the leaderboard data and the requesting user's position.
Description
This PR introduces a comprehensive gamification system, including a points mechanism, location-based leaderboards, and user suspension/blocking features. It also includes significant updates to the User model and related services.
Major Changes
Points System
PointsRepository
for managing user scoresLeaderboard Functionality
PointsRepository
getLeaderboard
andgetUserPosition
methods with location filteringPointsService
to handle leaderboard and user position logicUser Model and Repository Updates
user_score
,location_id
, andlocation
properties toUser
interfaceUserRepository
to handle new user propertiesSuspension and Blocking Features
suspendUserFromResolving
method to temporarily restrict user actionsblockUser
method for permanent restrictionsService Updates
IssueService
,CommentService
, andUserService
to integrate with new points systemImplementation Details
Points Awarding Rules
User Restrictions
Leaderboard and User Position
Testing
commentService.test.ts
,issueService.test.ts
, anduserService.test.ts
PointsRepository
andPointsService
API Changes
/api/points/leaderboard
for fetching leaderboardsHow to Use the Leaderboard Endpoint
This endpoint retrieves the leaderboard data and the requesting user's position.
Request Body:
Database Migrations
user_score
andlocation_id
columns to theuser
tablepoints_history
table for tracking point transactionsresolve_suspension_end
andis_blocked
columns to theuser
tableNEXT STEPS: