Skip to content

Conversation

@varun-suvarna-17
Copy link
Contributor

So in this problem i have made 3 files

  1. orderSchema -- basic template for buy and sell both
  2. orderController -- the main part so here i have 3 code blocks : placeBuyOrder , placeSellOrder and getUserOrders ( to display the users history of buying and selling)
  3. orderRoutes -- simply added the routes for the above 3 functions

Edited files -- mainRoutes i have included the path /orders thats it

now coming to testing part --

  1. i tested the functions using postman in vs code and fixed the errors and its working fine.....
  2. i added a test user locally in my local Db and used the local products data which i had stored using a test file seeder which i included in my last problem
  3. and it worked properly stored in the order file with the type name and also the get function worked when i tried to display the data of the test user

@SalmanNajah SalmanNajah changed the title Order Implementation of buy and sell Order Implementation of buy Jul 24, 2025
@SalmanNajah
Copy link
Collaborator

@varun-suvarna-17 I think we don't need the sell endpoint as it is already implemented in /listing (with type as sell)

@SalmanNajah
Copy link
Collaborator

Also change the /orders/buy endpoint just to /orders endpoint for simplicity, also the model need to be changed accordingly by removing the Type, it is by default considered as buy.


const order = new Order({
user,
type: "buy",
Copy link
Collaborator

Choose a reason for hiding this comment

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

type not needed

}
}

export async function placeSellOrder(req, res) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

sell endpoint not needed

ref: "social-logins",
required: true,
},
type: {
Copy link
Collaborator

Choose a reason for hiding this comment

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

type not needed

Comment on lines +6 to +7
router.post("/buy", placeBuyOrder);
router.post("/sell", placeSellOrder);
Copy link
Collaborator

Choose a reason for hiding this comment

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

these routes are not needed just have a / endpoint for buy


export async function placeBuyOrder(req, res) {
try {
console.log("Received body:", req.body); // 🔍 Debug incoming data
Copy link
Collaborator

Choose a reason for hiding this comment

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

comment out debug logs while pushing

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.

2 participants