1
0
mirror of https://github.com/microsoft/TypeScript-Node-Starter.git synced 2025-11-08 15:37:24 +00:00

Merge pull request #100 from Meir017/patch-2

use same signature for model function & ts type
This commit is contained in:
Bowden Kelly
2018-04-04 13:47:13 -07:00
committed by GitHub

View File

@@ -19,10 +19,12 @@ export type UserModel = mongoose.Document & {
picture: string
},
comparePassword: (candidatePassword: string, cb: (err: any, isMatch: any) => {}) => void,
comparePassword: comparePasswordFunction,
gravatar: (size: number) => string
};
type comparePasswordFunction = (candidatePassword: string, cb: (err: any, isMatch: any) => {}) => void;
export type AuthToken = {
accessToken: string,
kind: string
@@ -64,12 +66,13 @@ userSchema.pre("save", function save(next) {
});
});
userSchema.methods.comparePassword = function (candidatePassword: string, cb: (err: any, isMatch: any) => {}) {
const comparePassword: comparePasswordFunction = function (candidatePassword, cb) {
bcrypt.compare(candidatePassword, this.password, (err: mongoose.Error, isMatch: boolean) => {
cb(err, isMatch);
});
};
userSchema.methods.comparePassword = comparePassword;
/**
* Helper method for getting user's gravatar.
@@ -87,4 +90,4 @@ userSchema.methods.gravatar = function (size: number) {
// export const User: UserType = mongoose.model<UserType>('User', userSchema);
const User = mongoose.model("User", userSchema);
export default User;
export default User;