Skip to content

Instantly share code, notes, and snippets.

@nuelsoft
Created July 27, 2021 16:46
Show Gist options
  • Save nuelsoft/b7757995ae4ed3638c15ab601666ca87 to your computer and use it in GitHub Desktop.
Save nuelsoft/b7757995ae4ed3638c15ab601666ca87 to your computer and use it in GitHub Desktop.
const mongoose = require("mongoose");
class UserFrame {
constructor(data) {
this.id = data._id;
this.email = data.email;
}
get json() {
return {
id: this.id,
email: this.email
}
}
static get schema() {
return new mongoose.Schema({
email: String,
})
}
}
class UserRepository {
static model = mongoose.model("user", UserFrame.schema)
static async create(user) {
const instance = new UserRepository.model(user);
return await instance.save();
}
}
module.exports = {UserRepository, UserFrame}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment