Skip to content

implementation of API to record buying of an impact product#14

Open
shamoo53 wants to merge 1 commit intoRegen-Bazaar:mainfrom
shamoo53:API-to-record-buying-of-an-impact-product
Open

implementation of API to record buying of an impact product#14
shamoo53 wants to merge 1 commit intoRegen-Bazaar:mainfrom
shamoo53:API-to-record-buying-of-an-impact-product

Conversation

@shamoo53
Copy link

@shamoo53 shamoo53 commented Jul 5, 2025

📝 Description
This pull request introduces a new API feature to securely and efficiently record the purchase of an impact product (RWIP) in the system. The implementation ensures that every RWIP purchase is captured with complete transaction details, NFT metadata, and proper authentication, providing a solid foundation for future analytics, ownership tracking, and extensibility.

✅ Key Changes
Database Model Extension

The existing Transaction Mongoose schema has been extended to support NFT-specific details through a new nft subdocument.

The nft object includes:

tokenId: Unique NFT identifier.

name: NFT name (e.g., RWIP #1).

description: NFT description.

image: NFT image URL.

metadata: Flexible object for additional NFT information.

Dedicated Controller (rwipController.js)

Introduced a new purchaseRWIP function to handle RWIP purchase recording.

Responsibilities:

Validate required fields: buyer, seller, price, NFT details, transaction hash, etc.

Create and store the transaction as a nft_transfer type in the database.

Return the saved transaction in the response.

New Route (rwip.js)

Added a new POST route: /api/rwip/purchase.

The route is secured with authentication middleware to ensure only authorized users can record purchases.

The route is registered in the main API router (src/routes/index.js).

API Documentation (Updated README.md)

A new "RWIP" section has been added to the documentation.

Includes:

Endpoint: POST /api/rwip/purchase

Required Fields: buyerAddress, sellerAddress, price, NFT details, etc.

Sample Request & Response provided for developer guidance.

🔄 How It Works
When a user successfully buys a RWIP, the frontend sends a POST request to /api/rwip/purchase with the complete transaction and NFT information.

The backend validates and records the purchase in the Transaction collection with the appropriate fields.

All relevant details are persisted, including:

Buyer address

Seller address

Transaction hash

Purchase date

Price

NFT details (name, tokenId, metadata, image, etc.)

🎯 Benefits
Ensures traceability and accountability for every RWIP purchase.

Clean separation of concerns by introducing a dedicated controller and route.

Future-proof design for additional impact products or NFT integrations.

Strengthens security by enforcing authentication on purchase actions.

✅ Checklist
Transaction model extended with NFT details

Dedicated controller created

New authenticated route added

API documentation updated
Closes #11

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

package-lock.json can be removed

Copy link
Member

@pratiksardar pratiksardar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM , how can we try these out via postman or something ?
or how can we deploy it ? do you think supabase will be fine?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement API to record buying of an impact product

2 participants