Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | 2x 2x 2x 2x 2x 2x 2x 2x 2x | const mongoose = require('mongoose');
const hostEligibilityStatusSchema = new mongoose.Schema({
status: { type: String, enum: ['pending', 'approved', 'rejected'], default: 'pending' },
requestedAt: Date,
approvedBy: { type: mongoose.Schema.Types.ObjectId, ref: 'User' },
approvedAt: Date,
remarks: String,
}, { _id: false });
const eventHistorySchema = new mongoose.Schema({
hosted: [{ type: mongoose.Schema.Types.ObjectId, ref: 'Event' }],
attended: [{ type: mongoose.Schema.Types.ObjectId, ref: 'Event' }],
saved: [{ type: mongoose.Schema.Types.ObjectId, ref: 'Event' }],
waitlisted: [{ type: mongoose.Schema.Types.ObjectId, ref: 'Event' }],
}, { _id: false });
const referralStatsSchema = new mongoose.Schema({
sharedLinks: { type: Number, default: 0 },
successfulSignups: { type: Number, default: 0 }
}, { _id: false });
const verifierEligibilityStatusSchema = new mongoose.Schema({
approvedBy: { type: mongoose.Schema.Types.ObjectId, ref: 'User' },
approvedAt: Date,
remarks: String,
}, { _id: false });
const userSchema = new mongoose.Schema({
name: { type: String, required: true },
email: { type: String, required: true, unique: true, match: /\.(ac|edu)\.in$|\.edu$/ },
phone: { type: String, required: true },
Gender: { type: String },
DOB: { type: Date },
passwordHash: { type: String, required: true },
profilePhoto: { type: String },
institutionId: { type: mongoose.Schema.Types.ObjectId, ref: 'Institution' },
institutionVerificationStatus: { type: String, enum: ['pending', 'verified', 'rejected'], default: 'pending' },
collegeIdNumber: { type: String },
roles: { type: [String], default: ['student'] },
isVerified: { type: Boolean, default: false },
canHost: { type: Boolean, default: false },
hostEligibilityStatus: hostEligibilityStatusSchema,
verifierEligibilityStatus: verifierEligibilityStatusSchema,
interests: [String],
skills: [String],
learningGoals: [String],
badges: [String],
referralStats: referralStatsSchema,
eventHistory: eventHistorySchema,
lastLogin: Date,
createdAt: { type: Date, default: Date.now },
updatedAt: { type: Date, default: Date.now },
deletionRequestedAt: { type: Date },
deletionScheduledFor: { type: Date },
notificationPreferences: {
email: {
rsvp: { type: Boolean, default: true },
certificate: { type: Boolean, default: true },
cohost: { type: Boolean, default: true },
event_verification: { type: Boolean, default: true },
host_request: { type: Boolean, default: true }
},
inApp: {
rsvp: { type: Boolean, default: true },
certificate: { type: Boolean, default: true },
cohost: { type: Boolean, default: true },
event_verification: { type: Boolean, default: true },
host_request: { type: Boolean, default: true }
}
},
});
userSchema.pre('save', function (next) {
this.updatedAt = Date.now();
next();
});
userSchema.index({ institutionId: 1 });
module.exports = mongoose.model('User', userSchema);
|