This repository has been archived on 2022-05-17. You can view files and clone it, but cannot push or open issues or pull requests.
brainlet/models/User.js

42 lines
No EOL
963 B
JavaScript
Executable file

const config = require('../config');
const mongoose = require('mongoose');
const userSchema = new mongoose.Schema({
username: String,
password: String,
email: String,
role: String
});
userSchema.method('getPublicObject', function() {
return {
username: this.username,
permissionLevel: config.roleMap[this.role],
role: this.role,
_id: this._id
}
});
userSchema.method('getFullObject', function() {
return {
username: this.username,
password: this.password,
email: this.email,
permissionLevel: config.roleMap[this.role],
role: this.role,
_id: this._id
}
});
const User = mongoose.model('User', userSchema);
User.findByUsername = async function(username) {
return await User.findOne({ username }).exec();
};
User.getPulicFields = function() {
return 'username role _id';
};
module.exports = User;