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

use same signature for model function & ts type

declare function signature only once
This commit is contained in:
Meir017
2018-03-22 21:21:31 +02:00
committed by GitHub
parent 994deeeb49
commit 4ec629b8da

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;