Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ const ensureAuth = require('./auth/ensure-auth')();

app.use(morgan('dev'));

// going forward, probably best just to `> npm i cors -S` and use that
// middleware
app.use((req, res, next) => {
console.log('setting cors headers');
const url = '*';
Expand Down
2 changes: 2 additions & 0 deletions lib/auth/ensure-role.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// don't leave unused files in project

module.exports = function getEnsureRole(...roles) {
const lookup = roles.reduce((lookup, role) =>{
lookup[role] = true;
Expand Down
8 changes: 8 additions & 0 deletions lib/routes/pet-snapshots.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ const petModel = require('../models/pet');
const petSnapshotModel = require('../models/pet-snapshot');

router
// best to put pet specific routes as part of parent url, ie:

// /api/pets/:id/snapshots

// and then still offer direct url for use with id:

// /api/snapshots/:id

.get('/:animalId/all', bodyParser, (req, res, next) => {
//get all data related to a specific pet
const animalId = req.params.animalId;
Expand Down
4 changes: 3 additions & 1 deletion lib/routes/pets.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const router = require('express').Router();
const bodyParser = require('body-parser').json();
const userModel = require('../models/user');
// I prefer: `Pet` because then `new Pet()` makes more sense
const petModel = require('../models/pet');

router
Expand Down Expand Up @@ -43,6 +44,7 @@ router
.catch(next);
})
.post('/', bodyParser, (req, res, next) => {
// nice destructuring :)
const {_id, user} = req.user;
req.body.usernameId = _id;
req.body.owner = user;
Expand All @@ -56,7 +58,7 @@ router
petModel
.findByIdAndUpdate(req.params.id, req.body, {
new: true,
runValidators: true //not sure if need this
runValidators: true //not sure if need this. yes if you want updates to run schema validation!
})
.then(savedPet => {
res.send(savedPet);
Expand Down
2 changes: 2 additions & 0 deletions lib/routes/tests.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// not sure why this file is here...

const router = require('express').Router();
const bodyParser = require('body-parser').json();

Expand Down
2 changes: 1 addition & 1 deletion lib/routes/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const ensureAuth = require('../auth/ensure-auth')();
const ensureRole = require('../auth/ensure-role');

router
.post('/validate', ensureAuth, bodyParser, (req, res, next) => { //eslint-disable-line
.post('/validate', ensureAuth, bodyParser, (req, res) => {
res.send({valid:true, username: req.user.user});
})
.post('/signup', bodyParser, (req, res, next) => {
Expand Down
5 changes: 5 additions & 0 deletions test/test-setup-mongoose.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
// If you want to use this functionality in two places,
// change the export to a function that can be called with
// dbURI. Don't cut and paste entire file :(


const mongoose = require( 'mongoose' );

// we need a URI that points to our database
Expand Down