Implemented Loyalty Points System with Schema, Controllers, and Routes #968
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR adds the schema, controller, and routes needed to implement a loyalty points system. The system enables users to earn, manage, and redeem loyalty points based on eligible actions within the application, such as purchases.
Changes
Loyalty Points Schema
The
LoyaltyPoints
schema defines the structure for storing loyalty points for each user. This schema includes:userId
: (ObjectId) A reference to the user who has earned the points, allowing connection with the user database.points
: (Number) The total points awarded for a specific action.earnedBy
: (String) The source or action for earning points, such as"purchase"
or other actions defined in the application.timestamp
: (Date) The date and time when the points were awarded to track the user's point history over time.The schema captures each transaction as a record, enabling comprehensive tracking of point awards for auditing and user reference.
Controllers
loyaltyPointsController
: Manages the core functionality for loyalty points:awardPoints
: Adds points for a specific user action.getBalance
: Retrieves the current point balance for a user.getTransactionHistory
: Provides a list of all point transactions for a user.redeemPoints
: Allows a user to redeem available points.filterTransactions
: Filters point transactions by type, such as "purchase."Middleware
Routes
Defines API routes to interact with the loyalty points system, such as awarding, viewing, and redeeming points.
Endpoints
POST /api/loyalty-points
: Award points to a user for an eligible action.GET /api/loyalty-points
: Retrieve a user's loyalty point balance.GET /api/loyalty-points/transactions
: View the transaction history for a user's loyalty points.PUT /api/loyalty-points/:id
: Update the loyalty points for a user.DELETE /api/loyalty-points/:id
: Remove loyalty points from a user.GET /api/loyalty-points/filter/:type
: Filter transactions based on the type (e.g., "purchase").POST /api/loyalty-points/redeem
: Redeem points for a user.GET /api/loyalty-points/summary
: Get an overview of loyalty points for a user.Related Issues