Giter Club home page Giter Club logo

wesell's Introduction

WeSell

WeSell is a mockup e-commerce website/CRUD appliction where the products can be added to cart.

Technologies

This was made using Node.Js, EJS, Bootstrap and MongoDb. here is what the hoem page looks like: ![](/images/Screen Shot 2021-10-08 at 9.39.49 AM.png)

iceox

  1. I am hoping to have the delete functionality all set up
  2. and move to payment functionality the
  3. I want to see if clients can update their review

wesell's People

Contributors

t4r4n3h avatar

Watchers

 avatar

wesell's Issues

Feedback & Comments

Hey Tara! Great work on this project!! Here's my comments and feedback:

Double creating!

In your controller, you're creating the same thing twice!

async function create(req, res){
if (!req.user) {
return res.redirect('/auth/google')
}
const newProduct = new Product(req.body);
console.log('this is the NEW PRODUCT logged:',newProduct);
console.log('This is REQ.BODY', req.body)
await Product.create({
image: req.body.image,
name: req.body.name,
desc: req.body.desc,
qty: req.body.qty,
price: req.body.price,
})

Remember that with Mongoose, we have two ways of creating things in our database:

  1. Creating a new object in memory with let object = new Model(), and then calling object.save() on it to actually send it back to our database or
  2. Using the mongoose Model.create() method, which will actually do both of those steps in one.

The way your code is set up now, that newProduct is absolutely useless! We're creating it in memory, but then not saving it. Make sure you give the lessons or The Docs if you need some more clarification.

Delete Functionality

You were so close with your delete function, and I think a little bit more console logging would have gotten you there!

function delCart(req,res,next){
console.log ('req.user',req.user)
let cart= req.user.cart
let idx = cart.findIndex(function (item){
console.log('this is item:'. item)
item.equals(req.params.id)
})
console.log('this is the index',idx)
//i wasnt to write a splice method and save but the index # logging is always a -1
}

Your cart variable is going to be an array of objects, and therefore, the item variable inside of your findIndex callback is going to be an object. So if you want to compare the id of that object to the id that you have in your req.params, then you'd have to change your code around so you're comparing item.id with req.params.id. That's why that method is constantly returning -1, because you're checking if an object is equal to a string (which obviously, will always fail)

Stay RESTful!

You got one route that isn't following RESTful conventions. Remember that when we're sending data with the intent of creating something in our database, we would want to send it as a POST request, or if we're updating something, it would be a PUT request. This is up to you in how you want to route this particular request, but it won't be a GET request!

router.get('/cart/:id',userCtrl.addToCart);

Great work, and as always, let me know if you have questions about this feedback!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.