-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SeedDB script is working now #93
Changes from all commits
7767e84
e8e609e
96a13c5
ca62519
19929f0
61f882e
2333d44
f34dda8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,33 +8,33 @@ const userSchema = new Schema({ | |
username: { | ||
type: String, | ||
required: true, | ||
index: { unique: true } | ||
index: { unique: true }, | ||
}, | ||
name: { | ||
type: Schema.Types.ObjectId, | ||
ref: 'Name', | ||
required: true | ||
required: true, | ||
}, | ||
email: { type: String, required: true }, | ||
password: { type: String, required: true }, | ||
phone: String, | ||
// Check below fields, if present, user is of that type | ||
_donor: { | ||
type: Schema.Types.ObjectId, | ||
ref: 'Donor' | ||
ref: 'Donor', | ||
}, | ||
_family: { | ||
type: Schema.Types.ObjectId, | ||
ref: 'Family' | ||
ref: 'Family', | ||
}, | ||
_organizer: { | ||
type: Schema.Types.ObjectId, | ||
ref: 'Organizer' | ||
} | ||
ref: 'Organizer', | ||
}, | ||
}); | ||
|
||
// Hash password before saving | ||
userSchema.pre('save', next => { | ||
userSchema.pre('save', function(next) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we losing the arrow functions? shouldn't this be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As per the official mongoose docs:
|
||
bcrypt.hash(this.password, saltRounds, (err, hash) => { | ||
if (err) return next(err); | ||
this.password = hash; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just curious but why did you change this to inline?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only one item, can fit in one line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a prettier preset. I think 80 characters is the limit for making line breaks. All the formatting changes were auto-saved by prettier so there is a lot of noise :(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gotcha, thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this prettier preset remove use of arrow functions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No it doesn't, but it defaults to a style of
param => { ... }
instead of(param) => { ... }
. The methods on the models use a traditional function because I believe those methods will needthis
to point to the model in order to do stuff.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For multiple params, it will always be in
(param1, param2) => {}
because javascript requires that.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, i saw some arrow functions on the other files. i saw one change from () => {} to function() {}.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In most cases, we can use arrow functions but there are a few edge cases where we need a
function
declaration in order to accessthis
correctly or accessingarguments
within the function.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still figuring those edge cases out. I remember some guys running into issues at work with 'this' binding in es5.