Files
gameno-api/components/users/userModel.js
T
kavehhn bf5e66fa95 feat: add append-only course/user data import and expand user profile
Support uploading structured JSON to create courses, classes, and students without wiping existing data, and merge user name fields while adding gender and registration details from source sheets.
2026-08-15 01:31:44 +03:30

115 lines
2.0 KiB
JavaScript

// /components/users/userModel.js
const mongoose = require('mongoose');
const refreshTokenSchema = new mongoose.Schema({
token: { type: String, required: true },
expiresAt: { type: Date, required: true },
createdAt: { type: Date, default: Date.now }
});
const userSchema = new mongoose.Schema({
nationalIdCode: {
type: String,
required: true,
unique: true,
trim: true,
index: true
},
name: {
type: String,
required: true,
trim: true
},
gender: {
type: String,
enum: ['male', 'female'],
trim: true
},
phoneNumber: {
type: String,
required: true,
unique: true,
trim: true,
index: true
},
preferredMessenger: {
type: [{
type: String,
enum: ['Bale', 'WhatsApp', 'Telegram', 'SMS', 'Email']
}],
default: ['SMS']
},
email: {
type: String,
sparse: true,
trim: true,
lowercase: true,
match: [/^\w+([.-]?\w+)*@\w+([.-]?\w+)*(\.\w{2,3})+$/, 'Please fill a valid email address']
},
address: {
type: String,
trim: true
},
birthCertificateNumber: {
type: String,
trim: true
},
postalCode: {
type: String,
trim: true
},
placeOfIssue: {
type: String,
trim: true
},
fatherName: {
type: String,
trim: true
},
birthDate: {
type: Date
},
education: {
type: String,
trim: true
},
parentPhoneNumber: {
type: String,
trim: true
},
username: {
type: String,
required: true,
unique: true,
trim: true,
index: true
},
passwordHash: {
type: String,
required: true
},
role: {
type: mongoose.Schema.Types.ObjectId,
ref: 'Role',
required: true
},
courses: [{
type: mongoose.Schema.Types.ObjectId,
ref: 'Course'
}],
certificates: [{
type: mongoose.Schema.Types.ObjectId,
ref: 'Certificate'
}],
refreshTokens: [refreshTokenSchema],
isActive: {
type: Boolean,
default: true
}
}, {
timestamps: true
});
module.exports = mongoose.model('User', userSchema);