| import { Document, Schema, Model, model, Types } from 'mongoose'; |
|
|
| interface IGeoLocation { |
| type: "Point"; |
| coordinates: [number, number]; |
| } |
|
|
| interface IOrganizationDocs { |
| registrationCertificate?: string; |
| gstCertificate?: string; |
| authorizationLetter?: string; |
| additionalDocs?: string[]; |
| } |
|
|
| |
| export interface IUser extends Document { |
| username: string; |
| email: string; |
| password: string; |
| |
| usedOAuth?: boolean; |
| profilePhoto?: string; |
| lastActive?: Date; |
| isActive: boolean; |
|
|
| |
| twoFactorSecret?: string; |
| isTwoFactorEnabled?: boolean; |
|
|
| |
| location?: IGeoLocation; |
|
|
| role: "trainer" | "trainee" | "organization" | "admin"; |
|
|
| |
| organizationType?: "NDMA" | "SDMA" | "ATI" | "NGO" | "OTHER"; |
| documents?: IOrganizationDocs; |
| verificationStatus?: "pending" | "approved" | "rejected"; |
| verifiedBy?: Types.ObjectId; |
| documentsUploaded?: boolean; |
|
|
| |
| organization?: Types.ObjectId; |
| organizationVerificationStatus?: "pending" | "verified" | "rejected"; |
| govtIdCard?: string; |
| workDesignation?: string; |
| rejectionReason?: string; |
|
|
| |
| traineeCategory?: "community_volunteer" | "govt_officer" | "responder" | "student" | "other"; |
|
|
| |
| permissions?: string[]; |
|
|
| resetPasswordToken?: string; |
| resetPasswordExpires?: Date | number; |
|
|
| createdAt: Date; |
| updatedAt: Date; |
| } |
|
|
| const UserSchema = new Schema<IUser>({ |
| username: { |
| type: String, |
| required: true, |
| unique: true, |
| }, |
| email: { |
| type: String, |
| required: true, |
| unique: true, |
| lowercase: true, |
| }, |
| password: { |
| type: String, |
| required: false, |
| }, |
| resetPasswordToken: { |
| type: String, |
| default: null |
| }, |
| resetPasswordExpires: { |
| type: Date, |
| default: null |
| }, |
| usedOAuth: { |
| type: Boolean, |
| required: false |
| }, |
| profilePhoto: { |
| type: String, |
| default: 'https://www.gravatar.com/avatar/?d=mp', |
| }, |
| lastActive: { |
| type: Date, |
| default: Date.now, |
| }, |
| isActive: { |
| type: Boolean, |
| default: true, |
| }, |
| twoFactorSecret: { |
| type: String, |
| }, |
| isTwoFactorEnabled: { |
| type: Boolean, |
| default: false, |
| }, |
| role: { |
| type: String, |
| enum: ["trainer", "trainee", "organization", "admin"], |
| required: true |
| }, |
| documents: { |
| registrationCertificate: String, |
| gstCertificate: String, |
| authorizationLetter: String, |
| additionalDocs: [String] |
| }, |
| verificationStatus: { |
| type: String, |
| enum: ["pending", "approved", "rejected"], |
| default: "pending" |
| }, |
| verifiedBy: { |
| type: Schema.Types.ObjectId, |
| ref: "User" |
| }, |
| documentsUploaded: { |
| type: Boolean, |
| default: false |
| }, |
|
|
| organizationVerificationStatus: { |
| type: String, |
| enum: ["pending", "verified", "rejected"], |
| default: "pending" |
| }, |
|
|
| govtIdCard: String, |
| workDesignation: String, |
| rejectionReason: String, |
|
|
| |
| |
| |
| location: { |
| type: { |
| type: String, |
| enum: ["Point"], |
| default: "Point" |
| }, |
| coordinates: { |
| type: [Number], |
| default: [0, 0] |
| } |
| }, |
|
|
| |
| |
| |
| permissions: { |
| type: [String], |
| default: [] |
| }, |
|
|
| |
| |
| |
| organization: { |
| type: Schema.Types.ObjectId, |
| ref: "User" |
| }, |
|
|
| |
| |
| |
| traineeCategory: { |
| type: String, |
| enum: [ |
| "community_volunteer", |
| "govt_officer", |
| "responder", |
| "student", |
| "other" |
| ], |
| required: false |
| } |
|
|
| }, { timestamps: true }); |
|
|
| |
| UserSchema.index({ location: "2dsphere" }); |
|
|
| |
| UserSchema.index({ organization: 1 }); |
|
|
| |
| UserSchema.index({ verificationStatus: 1 }); |
|
|
| |
| UserSchema.index({ role: 1 }); |
|
|
| const User: Model<IUser> = model<IUser>('User', UserSchema); |
| export default User; |