user.ts 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import { Document, model, Schema, Types } from 'mongoose';
  2. import { IDomain } from './domain';
  3. export interface IUser extends Document {
  4. apikey?: string;
  5. banned?: boolean;
  6. bannedBy?: Types.ObjectId;
  7. cooldowns?: Date[];
  8. createdAt?: Date;
  9. domain?: Types.ObjectId | IDomain;
  10. email: string;
  11. password: string;
  12. resetPasswordExpires?: Date;
  13. resetPasswordToken?: string;
  14. updatedAt?: Date;
  15. verificationExpires?: Date;
  16. verificationToken?: string;
  17. verified?: boolean;
  18. }
  19. const UserSchema: Schema = new Schema({
  20. apikey: { type: String, unique: true },
  21. banned: { type: Boolean, default: false },
  22. bannedBy: { type: Schema.Types.ObjectId, ref: 'user' },
  23. cooldowns: [Date],
  24. createdAt: { type: Date, default: Date.now },
  25. domain: { type: Schema.Types.ObjectId, ref: 'domain' },
  26. email: {
  27. type: String,
  28. required: true,
  29. trim: true,
  30. lowercase: true,
  31. unique: true,
  32. },
  33. password: { type: String, required: true },
  34. resetPasswordExpires: { type: Date },
  35. resetPasswordToken: { type: String },
  36. updatedAt: { type: Date, default: Date.now },
  37. verificationExpires: { type: Date },
  38. verificationToken: { type: String },
  39. verified: { type: Boolean, default: false },
  40. });
  41. const User = model<IUser>('user', UserSchema);
  42. export default User;