Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented Loyalty Points System with Schema, Controllers, and Routes #968

Merged
merged 3 commits into from
Nov 10, 2024

Conversation

IkkiOcean
Copy link
Contributor

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

  1. 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.

  2. 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."
  3. Middleware

    • Validation middleware to ensure actions for points are valid.
    • Middleware to prevent duplicate claims of points for the same eligible action.
  4. Routes
    Defines API routes to interact with the loyalty points system, such as awarding, viewing, and redeeming points.


Endpoints

  1. Loyalty Points Routes
    • 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

Copy link

vercel bot commented Nov 10, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
agro-tech-ai ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 10, 2024 3:31am

Copy link
Contributor

Thank you for submitting your pull request! 🙌 We'll review it as soon as possible. In the meantime, please ensure that your changes align with our CONTRIBUTING.md. If there are any specific instructions or feedback regarding your PR, we'll provide them here. Thanks again for your contribution! 😊

@manikumarreddyu manikumarreddyu merged commit ad03026 into manikumarreddyu:main Nov 10, 2024
3 checks passed
Copy link
Contributor

🎉 Your pull request has been successfully merged! 🎉 Thank you for your valuable contribution to our project. Your efforts are greatly appreciated. Feel free to reach out if you have any more contributions or if there's anything else we can assist you with. Keep up the fantastic work! 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement Loyalty Points and Referral System: Schema, Controllers, Middleware, and Routes
2 participants