Skip to content

Instantly share code, notes, and snippets.

@velotiotech
Created October 8, 2020 10:47
Embed
What would you like to do?
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