Could you please review my code and provide any suggestions for improvement? I have two types of user roles, candidate and business, each with multiple unique fields. My goal is to consolidate all these fields into one userModel.ts file.
import mongoose from 'mongoose';
const userSchema = new mongoose.Schema({
email: {
type: String,
required: true,
unique: true,
},
password: {
type: String,
required: true,
},
role: {
type: String,
enum: ['candidate', 'business'],
required: true,
},
// ... Other common fields for both roles
// Define optional specific fields for each role (if any)
candidateSpecific?: {
// Candidate-specific fields (optional)
},
businessSpecific?: {
// Business-specific fields (optional)
},
});
export default mongoose.models.users || mongoose.model('users', userSchema);