mirror of
https://github.com/Alvin-Zilverstand/Challenge_15_Magazijn_App_Maken.git
synced 2026-03-06 21:29:20 +01:00
init
This commit is contained in:
34
models/User.js
Normal file
34
models/User.js
Normal file
@@ -0,0 +1,34 @@
|
||||
const mongoose = require('mongoose');
|
||||
|
||||
const userSchema = new mongoose.Schema({
|
||||
username: {
|
||||
type: String,
|
||||
required: true,
|
||||
unique: true
|
||||
},
|
||||
password: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
email: {
|
||||
type: String,
|
||||
required: function() {
|
||||
return this.role === 'student';
|
||||
},
|
||||
sparse: true,
|
||||
unique: true,
|
||||
validate: {
|
||||
validator: function(email) {
|
||||
return /^\d{6}@vistacollege\.nl$/.test(email);
|
||||
},
|
||||
message: 'Email must be in the format: 123456@vistacollege.nl'
|
||||
}
|
||||
},
|
||||
role: {
|
||||
type: String,
|
||||
enum: ['admin', 'student'],
|
||||
required: true
|
||||
}
|
||||
}, { timestamps: true });
|
||||
|
||||
module.exports = mongoose.model('User', userSchema);
|
||||
Reference in New Issue
Block a user