created Api to get seller profile#16
Conversation
|
@pratiksardar a pr has been sent kindly review |
|
can you create a postman collection or something so It's easy to understand the implementation , args and etc |
There was a problem hiding this comment.
Pull Request Overview
This PR introduces a new seller profile API that allows users to retrieve information about their projects and sales activity. The implementation adds comprehensive seller-related endpoints to track project creation, sales, and transaction history.
Key changes:
- Created new seller routes with authentication middleware for project management endpoints
- Extended the Transaction model to support project sales tracking with seller and project references
- Added a new Project model to represent sellable items with status tracking
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/routes/seller.js | New route file defining seller-specific endpoints with authentication |
| src/routes/index.js | Integration of seller routes into the main API routing structure |
| src/models/Transaction.js | Enhanced transaction model to support project sale tracking |
| src/models/Project.js | New project model for managing sellable items and their lifecycle |
| src/controllers/sellerController.js | Business logic for seller profile endpoints including projects and activity |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.
| createdAt: { | ||
| type: Date, | ||
| default: Date.now, | ||
| }, |
There was a problem hiding this comment.
The timestamps option is redundant since you already have explicit createdAt field. Either remove the explicit createdAt field and rely on timestamps: true, or remove the timestamps option to avoid confusion.
| }, |
| Project.find({ seller: sellerId }), | ||
| Transaction.find({ seller: sellerId, type: 'project_sale' }).populate('project'), | ||
| Transaction.find({ seller: sellerId }) | ||
| ]); |
There was a problem hiding this comment.
The getSellerActivity function performs redundant queries. The soldProjects query is a subset of the transactions query (transactions with type: 'project_sale'), so you could filter the transactions result instead of making a separate database call.
| ]); | |
| const [projects, transactions] = await Promise.all([ | |
| Project.find({ seller: sellerId }), | |
| Transaction.find({ seller: sellerId }).populate('project') | |
| ]); | |
| const soldProjects = transactions.filter(tx => tx.type === 'project_sale'); |
| try { | ||
| const sellerId = req.user.id; | ||
|
|
||
| const soldProjects = await Transaction.find({ seller: sellerId, type: 'project_sale' }).populate('project'); |
There was a problem hiding this comment.
[nitpick] The API returns Transaction objects for sold projects, but users might expect Project objects with sale information. Consider restructuring to return projects with their sale transaction details instead.
| const soldProjects = await Transaction.find({ seller: sellerId, type: 'project_sale' }).populate('project'); | |
| const soldTransactions = await Transaction.find({ seller: sellerId, type: 'project_sale' }).populate('project'); | |
| const soldProjects = soldTransactions | |
| .filter(tx => tx.project) // Ensure project is populated | |
| .map(tx => { | |
| const projectObj = tx.project.toObject ? tx.project.toObject() : { ...tx.project }; | |
| projectObj.saleInfo = { | |
| transactionId: tx._id, | |
| soldAt: tx.createdAt, | |
| price: tx.amount, | |
| buyer: tx.buyer, | |
| // add other relevant transaction fields as needed | |
| }; | |
| return projectObj; | |
| }); |
Created API to Get All Seller Created project, Sold Projects and other activity accordingly