Install npm dependencies:
cd into project
npm install
npm run start
The models folder found here include models for order, product, and user. Some example code is below.
const Schema = mongoose.Schema;
const orderSchema = new Schema({
products: [
{
product: { type: Object, required: true },
quantity: { type: Number, required: true }
}
],
user: {
email: {
type: String,
required: true
},
userId: {
type: Schema.Types.ObjectId,
required: true,
ref: 'User'
}
}
});
const store = new MongoDBStore({
uri: MONGODB_URI,
collection: 'sessions'
});
GET requests are located in the routes which includes
router.get('/', shopController.getIndex);
router.get('/products', shopController.getProducts);
router.get('/products/:productId', shopController.getProduct);
router.get('/edit-product/:productId', isAuth, adminController.getEditProduct);
POST requests are located in the admin.js file
router.post('/add-product', isAuth, adminController.postAddProduct);
The DELETE product is found in the admin.js file which is a post request which calls the postDeleteProduct controller
router.post('/delete-product', isAuth, adminController.postDeleteProduct);
exports.postDeleteProduct = (req, res, next) => {
const prodId = req.body.productId;
Product.findByIdAndRemove(prodId)
.then(() => {
console.log('DESTROYED PRODUCT');
res.redirect('/admin/products');
})
.catch(err => console.log(err));
};