Created
September 13, 2020 20:00
-
-
Save kingsley-einstein/cdfd560da3f824b685c4cb63fed0d102 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 mongoose from "mongoose"; | |
export class AuthModel { | |
model: mongoose.Model<mongoose.Document, {}>; | |
constructor() { | |
this.define(); | |
} | |
private define() { | |
this.model = mongoose.model("User", new mongoose.Schema({ | |
username: { | |
type: String, | |
required: true | |
}, | |
password: { | |
type: String, | |
required: true | |
} | |
}, { | |
timestamp: true | |
})); | |
} | |
create(body: any): Promise<mongoose.Document> { | |
return Promise.resolve( | |
this.model.create(body) | |
); | |
} | |
findByUsername(username: string): Promise<mongoose.Document> { | |
return Promise.resolve( | |
this.model.findOne({ username }) | |
); | |
} | |
findById(id: any): Promise<mongoose.Document> { | |
return Promise.resolve( | |
this.model.findById(id) | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment