Skip to content

Instantly share code, notes, and snippets.

@nuelsoft
Created July 27, 2021 16:48
Show Gist options
  • Save nuelsoft/caefcb84f4187fe026dd96e06d6b84aa to your computer and use it in GitHub Desktop.
Save nuelsoft/caefcb84f4187fe026dd96e06d6b84aa to your computer and use it in GitHub Desktop.
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