Skip to content

Instantly share code, notes, and snippets.

@velotiotech
Created October 8, 2020 10:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save velotiotech/d79a4032b0dc5cefc8da44c8577f95ad to your computer and use it in GitHub Desktop.
Save velotiotech/d79a4032b0dc5cefc8da44c8577f95ad to your computer and use it in GitHub Desktop.
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