Created
July 27, 2021 16:48
-
-
Save nuelsoft/caefcb84f4187fe026dd96e06d6b84aa 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
class SessionFrame { | |
constructor(data) { | |
this.id = data._id; | |
this.device_id = data.device_id; | |
this.user = data.user; | |
} | |
get json() { | |
return { | |
id: this.id, | |
device_id: this.device_id, | |
user: this.user | |
} | |
} | |
static get schema() { | |
return new mongoose.Schema({ | |
device_id: String, | |
user: String, | |
deactivated: Boolean | |
}) | |
} | |
} | |
class SessionRepository { | |
static model = mongoose.model("session", SessionFrame.schema) | |
static async create(user) { | |
const instance = new SessionRepository.model(user); | |
return await instance.save(); | |
} | |
static async getSession(id) { | |
/** | |
* Logic for retrieving session where `deactivated` is false | |
*/ | |
} | |
static async deactivate(id) { | |
/** | |
* Logic for deactivating sessions, | |
* Simply update the `deactivated` property to true. | |
*/ | |
} | |
} | |
module.exports = {SessionFrame, SessionRepository} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment