Download models/User.js from sverdlov/undefined: direct link, hf CLI and curl.
- Browser
- Download file 912 Bytes
-
https://huggingface.co/spaces/sverdlov/undefined/resolve/main/models/User.js
- Command line
-
hf download hf://spaces/sverdlov/undefined/models/User.js
-
curl -L -o User.js https://huggingface.co/spaces/sverdlov/undefined/resolve/main/models/User.js
912 Bytes
| ```javascript | |
| const mongoose = require('mongoose'); | |
| const bcrypt = require('bcryptjs'); | |
| const UserSchema = new mongoose.Schema({ | |
| name: { | |
| type: String, | |
| required: true | |
| }, | |
| email: { | |
| type: String, | |
| required: true, | |
| unique: true | |
| }, | |
| password: { | |
| type: String, | |
| required: true | |
| }, | |
| role: { | |
| type: String, | |
| enum: ['admin', 'manager', 'employee'], | |
| default: 'employee' | |
| }, | |
| department: { | |
| type: mongoose.Schema.Types.ObjectId, | |
| ref: 'Department' | |
| }, | |
| date: { | |
| type: Date, | |
| default: Date.now | |
| } | |
| }); | |
| UserSchema.pre('save', async function(next) { | |
| if (!this.isModified('password')) return next(); | |
| const salt = await bcrypt.genSalt(10); | |
| this.password = await bcrypt.hash(this.password, salt); | |
| next(); | |
| }); | |
| module.exports = mongoose.model('User', UserSchema); | |
| ``` |