View on GitHub

DevQuest 2024

DevQuest is an international hackathon organized under the tertiary category of CODEFEST, aimed at showcasing the unique talents, creativity, and innovations of undergraduates from universities and institutes worldwide.

Challenge 16

Overview

In this application users can send gift vouchers to each other. The user can send a gift voucher to another user by entering the recipient’s email address and the amount of the gift voucher. The recipient will receive the gift voucher in the gift voucher section of the application. The recipient can then claim the gift voucher. This challenge has 3 sub-challenges.

a. Send a gift voucher

In the application, the user should be able to send a gift voucher to another user. Use POST /api/gift-voucher to send a gift voucher. The request body should contain the receiverEmail and amount of the gift voucher. You can implement the sendGiftVoucher() function in the /controller/giftVoucherController.js file to send a gift voucher.

Instructions

** Tip - Implement the expiresAt calculation in the giftVoucher model in /models/giftVoucher.js file since it is a common calculation for all gift vouchers.

Request - POST /api/gift-voucher

{
  "receiverEmail": "johnS@gmail.com",
  "amount": 300
}

Response for POST /api/gift-voucher

{
  "data": {
    "id": "14ea3f7b-47b0-40fc-9cae-890f480b45aa",
    "amount": 300,
    "issuedAt": "2024-05-07T04:02:20.751Z",
    "expiresAt": "2024-05-21T04:02:20.751Z",
    "status": "unclaimed"
  }
}

b. Get gift vouchers for recipient

In the application the recipient should be able to view all the gift vouchers they have received. Use GET /api/gift-voucher/receiver to get all the gift vouchers for the recipient. You can implement the getGiftVouchersByReceiverId() function in the /controller/giftVoucherController.js file to get all the gift vouchers for the recipient.

Instructions

User id can be retried from req.user.

Response for GET /api/gift-voucher/receiver

{
    "data": [
        {
            "id": "ad8b570b-0084-4e6e-9f26-aa5f8c17fbc2",
            "senderId": "da9347a6-2a7f-4573-be27-15f05569fb0d",
            "receiverId": "c784dd78-b26e-4cc0-9c8a-b84bdb4330b9",
            "amount": 200,
            "issuedAt": "2024-04-10T11:37:01.316Z",
            "expiresAt": "2024-04-24T11:37:01.316Z",
            "status": "expired",
            "senderName": "Matt Damon"
        }
    ]
}

c. Claim a gift voucher

In the application the recipient should be able to claim a gift voucher. Use PATCH /api/gift-voucher/claim/:id to claim a gift voucher. You can implement the claimGiftVoucher() function in the /controller/giftVoucherController.js file to claim a gift voucher.

You can get the user id from the token, and you need to pass the voucher id as a path parameter in the URL.

Instructions