Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

174
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda