Skip to content

Conversation

@ameliavoncat
Copy link

No description provided.

Copy link
Contributor

@jrobcodes jrobcodes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -0,0 +1,23 @@
const mongoose = require('mongoose')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we name this file something that is more illustrative about what the file is responsible for? Models? Schema?

As well, I think we need to look at strategies for connecting to the DB once in the application, instead of opening new connections in each module - please connect with @harmanlearns and @jessehall3 to discuss.


mongoose.connect('mongodb://localhost/lizardboard')
const db= mongoose.connection
db.on('error', console.error.bind(console,'connection error:'))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is connection configuration stuff, probably belongs in a separate module (see comment above).

db.once('open', function() {
console.log('connected')
})

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra whitespace

const widgetSchema = mongoose.Schema ({
type: String, title: String, size: String, contents: String
})
const userSchema = mongoose.Schema ({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add whitespace. Having said that, two different Schemas should probably be defined in separate modules (along with their models, perhaps?).

username: String,
widgets: [ widgetSchema ]
})
const userWidgets = mongoose.model('userWidgets', userSchema)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Models should be singular UpperCamelCase.

)
})

/* UPDATE widgets */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove comment

})

/* UPDATE widgets */
router.post('/:userId/widgets/:widgetId/update', ( request, response, next ) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See note above about RESTful endpoints, removing upsert, etc.

userWidgets.findOneAndUpdate(
{ _id: userId, widgets: { $elemMatch:{ _id: widgetId }}},
{
$set: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't mongoose provide a much better API for updating than $set? If not, we're going to throw it out...

})


/* DELETE widgets */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove comment and extraneous whitespace.



/* DELETE widgets */
router.post( '/:userId/widgets/:widgetId/delete', ( request, response, next ) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See notes above re: REST, mongoose API, ES6.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants