Skip to content

MrDroid17/wallet-node-backend

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Backend Server URL: https://hglevel-wallet-server.onrender.com
Frontend URL: https://highlevel-wallet-ui.onrender.com

NOTE: First api hit can take upto 2 min as render service automatically sleeps due to inactivity

React UI: Frontend code link here

HighLevel Wallet Backend

Project Setup

  1. Clone the repository:

    • git clone https://github.com/MrDroid17/highlevel-wallet-backend.git
    • cd highlevel-wallet-backend
  2. Install dependencies:

    • npm install
  3. Create a .env file with your environment variables:

        API_PORT=9091
        MONGODB_URI=your_mongodb_connection_string
  4. Start the development server:

    • npm run start:dev

Environment Setup

Make sure you have Node.js and MongoDB installed(Can also use cloud mongoDB such as MongoDb atlas). Update .env with your credentials.

Live Server

Technology Used:

  • Database: MongoDB Atlas
  • Backend Technology: Node.js with express
    • Joi - request Validation
    • mongoose - MongoDB ORM for Schema and DB level validation
  • Backend Deployment: deployed on render.com
  • Frontend Technology: React.js
  • Frontend Deployment: deployed on render.com

API Details:

1. Wallet Setup and Initialization

Create new wallet with name and optional balance field.

Request URL

https://hglevel-wallet-server.onrender.com/wallet/setup

Request Type POST

Request Body

{
     "name": "walletXYZ",
     "balance": 80
}

Curl Example

curl --location 'https://hglevel-wallet-server.onrender.com/wallet/setup' \
--header 'Content-Type: application/json' \
--data '{
     "name": "walletXYZ",
     "balance": 80
}'

Response Example

{
     "id": "689fdff3dc1485f55beb8b0b",
     "balance": 80,
     "transactionId": "689fdff3dc1485f55beb8b0d",
     "name": "walletXYZ",
     "date": "2025-08-16T01:33:39.431Z"
}

2. CREDIT/DEBIT transaction

Create a transaction on wallet using walletId. -ve/+ve amount will tells the transaction type.

  • +ve amount is Credit
  • -ve amount is Debit
  • Amount can be decimal with only 4 precision point after decimal e.g. 45.4566, 12.3467
  • description can be optional
  • the path variable walledId and payload have proper validation

Request URL

https://hglevel-wallet-server.onrender.com/wallet/transact/689fdff3dc1485f55beb8b0b

Request Type POST

Request Body

{
    "description": "Recharge",
    "amount": 10
}

Curl Example

curl --location 'https://hglevel-wallet-server.onrender.com/wallet/transact/689fdff3dc1485f55beb8b0b' \
--header 'Content-Type: application/json' \
--data '{
    "description": "Recharge",
    "amount": 10
}'

Response Example

{
    "balance": 79,
    "transactionId": "689fe010dc1485f55beb8b15"
}

3. Get All transaction

Get all transaction for a wallet with pagination using skip and limit Query params:

  • walletId
  • skip
  • limit Proper validation has been added for all QueryParams. All three QueryParams are optional. in Case skip and limit is not provided all the transaction depending on if walletId is provided or not

Request URL

https://hglevel-wallet-server.onrender.com/wallet/transactions?walletId=689fdff3dc1485f55beb8b0b&skip=0&limit=10

Request Type GET

Curl Example

curl --location 'https://hglevel-wallet-server.onrender.com/wallet/transactions?walletId=689fdff3dc1485f55beb8b0b&skip=0&limit=10' \
--header 'Content-Type: application/json'

Response Example

[
    {
        "id": "689fe010dc1485f55beb8b15",
        "walletId": "689fdff3dc1485f55beb8b0b",
        "amount": 10,
        "balance": 79,
        "date": "2025-08-16T01:34:08.107Z",
        "description": "Recharge",
        "type": "CREDIT"
    },
    {
        "id": "689fe008dc1485f55beb8b11",
        "walletId": "689fdff3dc1485f55beb8b0b",
        "amount": 11,
        "balance": 69,
        "date": "2025-08-16T01:34:00.375Z",
        "description": "Recharge",
        "type": "DEBIT"
    },
    {
        "id": "689fdff3dc1485f55beb8b0d",
        "walletId": "689fdff3dc1485f55beb8b0b",
        "amount": 80,
        "balance": 80,
        "date": "2025-08-16T01:33:39.651Z",
        "description": "Initial new wallet setup",
        "type": "CREDIT"
    }
]

4. Get Wallet Details

Get wallet details by it walletId in params

  • Proper wallidation has been added for walletId

Request URL

https://hglevel-wallet-server.onrender.com/wallet/689fdff3dc1485f55beb8b0b

Request Type GET

Curl Example

curl --location 'https://hglevel-wallet-server.onrender.com/wallet/689fdff3dc1485f55beb8b0b' \
--header 'Content-Type: application/json'

Response Example

{
    "id": "689fdff3dc1485f55beb8b0b",
    "balance": 79,
    "name": "walletXYZ",
    "date": "2025-08-16T01:33:39.431Z"
}

Error handling or error responses

Invalid Route

-   Status Code: `404` Route Not Found
{
    "success": false,
    "message": "Route not found."
}

Validation Error

-   Status Code: `400` bad Request
{
    "message": "\"walletId\" with value \"689fdff3dc1485f55beb8b0\" fails to match the required pattern: /^[0-9a-fA-F]{24}$/"
}

Internal Server Error

-   Status Code: `500` 
{
    "message": "Transaction failed.", // where it failed
    "error": "MSG thrown by server"// server generic error
}

About

NodeJS backend

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors