aboutsummaryrefslogtreecommitdiff
path: root/src/model/User.ts
blob: e1784f21467ca32b55e1776425761ea59be57029 (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
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 } 
  }
}, {
  timestamps: true
});

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

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

export default User;