feat(professors,sms): merge professor with users, add existing user link, professor portal endpoint, and SMS bypass list
This commit is contained in:
@@ -1,45 +1,16 @@
|
||||
// /components/professors/professorModel.js
|
||||
'use strict';
|
||||
|
||||
const mongoose = require('mongoose');
|
||||
|
||||
const professorSchema = new mongoose.Schema({
|
||||
nationalIdCode: {
|
||||
type: String,
|
||||
user: {
|
||||
type: mongoose.Schema.Types.ObjectId,
|
||||
ref: 'User',
|
||||
required: true,
|
||||
unique: true,
|
||||
trim: true,
|
||||
index: true
|
||||
},
|
||||
name: {
|
||||
type: String,
|
||||
required: true,
|
||||
trim: true
|
||||
},
|
||||
surname: {
|
||||
type: String,
|
||||
required: true,
|
||||
trim: true
|
||||
},
|
||||
phoneNumber: {
|
||||
type: String,
|
||||
required: true,
|
||||
unique: true,
|
||||
trim: true,
|
||||
index: true
|
||||
},
|
||||
email: {
|
||||
type: String,
|
||||
trim: true,
|
||||
lowercase: true
|
||||
},
|
||||
cardNumber: {
|
||||
type: String,
|
||||
trim: true
|
||||
},
|
||||
shabaNumber: {
|
||||
type: String,
|
||||
trim: true
|
||||
},
|
||||
bio: {
|
||||
type: String,
|
||||
trim: true
|
||||
@@ -57,7 +28,62 @@ const professorSchema = new mongoose.Schema({
|
||||
default: true
|
||||
}
|
||||
}, {
|
||||
timestamps: true
|
||||
timestamps: true,
|
||||
toJSON: { virtuals: true },
|
||||
toObject: { virtuals: true }
|
||||
});
|
||||
|
||||
// Virtual properties delegating personal details to the linked User model
|
||||
professorSchema.virtual('name').get(function () {
|
||||
if (this.user && typeof this.user === 'object' && this.user.name) {
|
||||
return this.user.name;
|
||||
}
|
||||
return undefined;
|
||||
});
|
||||
|
||||
professorSchema.virtual('surname').get(function () {
|
||||
if (this.user && typeof this.user === 'object' && this.user.name) {
|
||||
const parts = String(this.user.name).trim().split(/\s+/);
|
||||
if (parts.length > 1) {
|
||||
return parts.slice(1).join(' ');
|
||||
}
|
||||
}
|
||||
return '';
|
||||
});
|
||||
|
||||
professorSchema.virtual('nationalIdCode').get(function () {
|
||||
if (this.user && typeof this.user === 'object') {
|
||||
return this.user.nationalIdCode;
|
||||
}
|
||||
return undefined;
|
||||
});
|
||||
|
||||
professorSchema.virtual('phoneNumber').get(function () {
|
||||
if (this.user && typeof this.user === 'object') {
|
||||
return this.user.phoneNumber;
|
||||
}
|
||||
return undefined;
|
||||
});
|
||||
|
||||
professorSchema.virtual('email').get(function () {
|
||||
if (this.user && typeof this.user === 'object') {
|
||||
return this.user.email;
|
||||
}
|
||||
return undefined;
|
||||
});
|
||||
|
||||
professorSchema.virtual('cardNumber').get(function () {
|
||||
if (this.user && typeof this.user === 'object') {
|
||||
return this.user.cardNumber;
|
||||
}
|
||||
return undefined;
|
||||
});
|
||||
|
||||
professorSchema.virtual('shabaNumber').get(function () {
|
||||
if (this.user && typeof this.user === 'object') {
|
||||
return this.user.shabaNumber;
|
||||
}
|
||||
return undefined;
|
||||
});
|
||||
|
||||
module.exports = mongoose.model('Professor', professorSchema);
|
||||
|
||||
Reference in New Issue
Block a user