GitXplorerGitXplorer
d

FullStack-JavaScript-Project-11--Node-Mongoose-Rest-Api

public
2 stars
0 forks
0 issues

Commits

List of commits on branch master.
Verified
cfbf332634ec3fe96b04cefe5d07ddca3c1cdb44

Delete package-lock.json

ddebs-obrien committed 7 years ago
Verified
22e45b0fe1bacc3e975c613c043b090f4b25473c

delete timeout

ddebs-obrien committed 7 years ago
Unverified
03dea7217b956930679065da205e5e3dfe32a0af

readme mod for install instructions

ddebs-obrien committed 7 years ago
Unverified
62d45f43a6670533a65edcf62c346edc046d3f54

readme

ddebs-obrien committed 7 years ago
Unverified
2968c3fdea039ffe8007606ed5ffd686667da342

refactoring

ddebs-obrien committed 7 years ago
Unverified
bdc76ba059ce6665e267189ce0dd1d9286d079db

2 tests working

ddebs-obrien committed 7 years ago

README

The README file for this repository.

Build a Course Rating API With Express

Team Tree House FullStack Project 11

Node, Express, Middleware, Mongo, Mongoose, Basic Auth, Mocha, Chai, JavaScript,

  • Set up a database connection using Mongoose
  • Create your Mongoose schema and models.
  • Seed your database with data. Use Mongoose seeder
  • Create the user routes, GET, POST
  • Create the course routes, GET, POST, PUT
  • Update any POST and PUT routes to return Mongoose validation errors.
  • Update the User model to store the user's password as a hashed value.
  • Create an authentication method on the user model to return the user document based on their credentials
  • Set up permissions to require users to be signed in
  • Validation added to prevent a user from reviewing their own course
  • Tests have been written for GET /api/users with and without credentials
  • Use Mongoose deep population to return only the fullName of the related user on the course model and each review returned with the course model
  • notified if any of the required fields in any given form have any missing data
  • Include pagination for the loans and books listing pages
  • Include search fields on at least one of the books or patrons listing pages

By Debbie O'Brien

20 October 2017

To run the application

npm install
mongod
npm start
use Postman to test routes
the app is served on port 3000

For testing create db testDB
npm test

Example Code

/*---------------------------------------------------------------------
POST user - creates a new user
check to see if that user exists by checking email in form against database
use schema's `create` method to insert document into Mongo
if user doesnt add a full name or email we cant create a user
 ----------------------------------------------------------------------*/
router.post('/', function(req, res, next) {
    User.findOne({emailAddress:req.body.emailAddress})
        .exec(function(err, user){
            if(user){
                err = new Error();
                err.message = 'That email already exists';
                err.status = 400;
                return next(err);
            }else{
                User.create(req.body, function (err, user) {
                    if(!user.emailAddress || !user.fullName || !user.password){
                        err.status = 400;
                        return next(err);
                    }
                    if (err){
                        return next(err);
                    } else{
                        res.location('/');
                        res.status(201).json();
                    }

                });
            }
        });
});