Skip to content

CobyYates/Dealership-RESTful-API

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Dealership RESTful CRUD Node Server

GraphQL

GraphQL

GraphQL

How to use

This project has a .env file for the MongoDB credentials which is not included in the GitHub Repo

1. Download example & install dependencies

Install npm dependencies:

cd into project
npm install

2. Run each npm script in package.json

npm run start

Project Requirements

Mongoose as your data modeling tool

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'
    }
  }
});

Cloud-based MongoDB as your data store

const store = new MongoDBStore({
  uri: MONGODB_URI,
  collection: 'sessions'
});

At least 3 endpoints to GET data from your server

GET requests are located in the routes which includes

admin.js
auth.js
shop.js

router.get('/', shopController.getIndex);

router.get('/products', shopController.getProducts);

router.get('/products/:productId', shopController.getProduct);

At least 1 endpoint allowing user to update an item via PUT or PATCH HTTP verbs

router.get('/edit-product/:productId', isAuth, adminController.getEditProduct);

At least 1 endpoint allowing user to create an item via POST

POST requests are located in the admin.js file

router.post('/add-product', isAuth, adminController.postAddProduct);

At least 1 endpoint allowing user to delete an item via DELETE

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));
};

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published