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 Gift Card System with Creation, Redemption, and Management Features #970

Merged
merged 1 commit into from
Nov 10, 2024

Conversation

IkkiOcean
Copy link
Contributor

Summary:

This PR implements a comprehensive gift card system for managing gift cards in the application. The system includes the following key functionalities:

  1. Schema: A schema to store gift card details such as card number, value, status (active, redeemed, expired), user association, and expiry date.
  2. Controller: Logic for creating, activating, redeeming, and fetching gift card details.
  3. Middleware: Validation middleware to check the validity and status of gift cards before redemption.
  4. Routes: API routes to handle creating, redeeming, and managing gift cards.

Details:

Endpoints:

  1. POST /api/gift-cards:

    • Description: Creates a new gift card with the specified value, associated user ID, and expiry date.
    • Request Body:
      • value: The monetary value of the gift card.
      • userId: The ID of the user associated with the gift card.
      • expiryDate: The expiry date of the gift card in ISO 8601 format.
    • Response: Returns the newly created gift card details.
  2. GET /api/gift-cards/:cardNumber:

    • Description: Fetches the details of a specific gift card using its unique card number.
    • Response: Returns gift card details including card number, value, status, user association, and expiry date.
  3. POST /api/gift-cards/redeem:

    • Description: Redeems a gift card by entering its card number.
    • Request Body:
      • cardNumber: The card number to be redeemed.
    • Middleware: Ensures the card is valid, not expired, and has not been redeemed.
    • Response: Returns a success message on redemption or an error message if redemption fails.
  4. GET /api/gift-cards/user/:userId:

    • Description: Fetches all gift cards associated with a specific user.
    • Response: Returns a list of gift cards for the user, with details like status, value, and expiry.
  5. GET /api/gift-cards/search:

    • Description: Allows searching for gift cards within a specified value range using query parameters minValue and maxValue.
    • Query Parameters:
      • minValue: Minimum value for the gift cards.
      • maxValue: Maximum value for the gift cards.
    • Response: Returns a list of gift cards within the specified value range.
  6. DELETE /api/gift-cards/:cardNumber:

    • Description: Forcefully deletes a gift card by its card number (admin-only functionality).
    • Response: Returns success or failure message indicating whether the card was deleted.
  7. PATCH /api/gift-cards/deactivate/:cardNumber:

    • Description: Marks a gift card as expired before redemption (admin or user-initiated expiration).
    • Response: Returns the updated status of the gift card.
  8. GET /api/gift-cards:

    • Description: Fetches all gift cards in the system (admin-only route).
    • Response: Returns a list of all gift cards with their details.
  9. GET /api/gift-cards/stats:

    • Description: Retrieves statistics on gift card usage, such as how many cards have been redeemed, active, and expired.
    • Response: Returns statistical data for analysis.

Schema:

The GiftCard schema is designed to store the necessary details of each gift card:

  • cardNumber: A unique identifier for each gift card.
  • value: The monetary value of the gift card.
  • status: Tracks the status of the gift card (active, redeemed, expired).
  • userId: Associates the gift card with a specific user.
  • expiryDate: The date when the gift card expires.
  • createdAt: The date when the gift card was created.

Middleware:

  • Validation Middleware for Redemption (giftCardMiddleware.js):
    • Ensures that a gift card can only be redeemed if:
      • It exists in the database.
      • It is not already redeemed.
      • It is not expired.
    • The middleware checks these conditions and passes control to the controller if the gift card is valid, or returns an appropriate error message otherwise.

Controllers:

  • GiftCardController:
    • createGiftCard: Handles the creation of new gift cards, assigning a value, user, and expiry date to the gift card.
    • getGiftCardDetails: Retrieves the details of a specific gift card based on its card number.
    • redeemGiftCard: Handles the redemption process, validating the gift card through middleware and updating its status.
    • getUserGiftCards: Fetches all the gift cards associated with a specific user.
    • searchGiftCardsByValue: Searches and returns gift cards within a specified value range.
    • deleteGiftCard: Forcefully deletes a gift card from the system by its card number.
    • deactivateGiftCard: Deactivates or expires a gift card before its redemption.
    • getAllGiftCards: Admin-only route to fetch all gift cards in the system.
    • getGiftCardStats: Retrieves statistics on gift card usage, such as how many have been redeemed, active, and expired.

Expected Outcome:

  • Functionality: The system enables users to create, manage, and redeem gift cards. Admins can manage all gift cards in the system, while users can view and redeem their cards.
  • Validation: The middleware ensures that only valid and active gift cards can be redeemed, and expired or already redeemed cards cannot be used.
  • Statistics: Admins have access to usage statistics to monitor gift card activity.

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 4:38am

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 ccb3461 into manikumarreddyu:main Nov 10, 2024
4 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 Gift Card System: Schema, Controller, Middleware, and Routes
2 participants