aboutsummaryrefslogtreecommitdiff
path: root/src/model/User.ts
blob: c5c81de0a5160cec15aa84d7afe65e189dce2acc (plain)
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
import { Schema, model, models, Document } from "mongoose";

const UserSchema = new Schema({
  name: { type: String, required: true },
  email: { type: String, required: true, unique: true },
  password: { type: String, required: true },
  profileImage: {
    url: { type: String },
    key: { type: String },
    uploadedAt: { type: Date } 
  },
  twoFactorEnabled: { type: Boolean, default: false },
  twoFactorSecret: { type: String }
}, {
  timestamps: true
});

UserSchema.set('toJSON', {
  transform: (_doc: Document, ret: Record<string, unknown>) => {
    delete ret.password;
    delete ret.twoFactorSecret;
    delete ret.__v;
    return ret;
  }
});

const User = models.User || model("User", UserSchema);

export default User;