Last active
September 13, 2020 20:16
-
-
Save kingsley-einstein/98e5b20fcde0788428369187c71b0d65 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 SessionModel { | |
model: mongoose.Model<mongoose.Document, {}>; | |
constructor() { | |
this.define(); | |
} | |
private define() { | |
this.model = mongoose.model("Session", new mongoose.Schema({ | |
sessionId: { | |
type: String | |
} | |
})); | |
} | |
invalidate(sessionId): Promise<mongoose.Document> { | |
return Promise.resolve( | |
this.model.create({ sessionId }) | |
); | |
} | |
async isInvalid(sessionId): Promise<boolean> { | |
const m = await this.model.findOne({ sessionId }); | |
return Promise.resolve(!!m); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment