Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

168
Views
I am making a prototype e-commerce website as a project, how do I specifically just show an authenticated user's orders?

As the title says I am a beginner learner who now got into learning the MERN stack. I am now currently using Node.js and Express for the server and about to create the client side in React. My problems are I don't know how to make all users' orders appear for the admin, and how to make all the user's checkouts appear to them but not the admin?

See the following photo on how a user's orders reflect on the database (MongoDB). I test using Postman. POSTMAN PHOTO

See also my code on my routes and controllers on how a user checkouts an item.

CONTROLLERS

//USER CHECKOUT
module.exports.co = async (buy) => {
    const {userId, productId} = buy

    const buying = await User.findById(userId).then(result => {result.order.push({productId: productId})
    
    return result.save().then(user => user ? true: false)
})

    const bought = await Product.findById(productId).then(result => {
        result.checkOut.push({userId: userId})
        
        return result.save().then(product => product ? true : false)
    })

    if(buying && bought) {
        return 'Item checked out.'
    } else {
        return 'Item not checked out.'
    }

}

ROUTE

//User check-out
router.put('/:_id/check-out', verify, async (req, res) => {
    const user = decode(req.headers.authorization).isAdmin
    const buy = {
        userId: decode(req.headers.authorization).id,
        productId: req.body.productId
    }
    if(user == false){
    try{
        await co(buy).then(result => res.send(result))
    }catch(err){
        res.status(500).json(err)
    }
}else {
    res.send(`Only registered users can purchase items.`)
}
})

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!