Created
October 8, 2020 10:47
-
-
Save velotiotech/d79a4032b0dc5cefc8da44c8577f95ad to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Document, Model, Schema } from "mongoose"; | |
import { db } from "../util/database"; | |
export interface IUserProps { | |
email: string; | |
firstName: string; | |
lastName: string; | |
password: string; | |
} | |
export interface IUserDocument extends IUserProps, Document { | |
} | |
export interface IUserModel extends Model<IUserDocument> { | |
dateCreated: Date; | |
lastUpdated: Date; | |
hashPassword(password: string): string; | |
} | |
const UserSchema: Schema = new Schema( | |
{ | |
email: { | |
type: String, | |
unique: true, | |
}, | |
firstName: { | |
type: String, | |
}, | |
password: { | |
type: String, | |
}, | |
}, | |
{ timestamps: true } | |
); | |
const hashPassword = (_password: string) => { | |
// logic to hash passwords | |
} | |
UserSchema.method("hashPassword", hashPassword); | |
export const User: IUserModel = db.model<IUserDocument, IUserModel>( | |
"User", | |
UserSchema | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment