File size: 890 Bytes
d50360d
 
433085e
 
d50360d
433085e
 
 
 
 
 
 
 
 
98d83e7
433085e
 
 
 
 
 
 
 
 
 
 
 
d50360d
 
433085e
 
 
d50360d
 
433085e
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
30
31
32
33
34
35
36
import mongoose from "mongoose";
import bcrypt from "bcrypt";
import { Role } from "../enums/roles.enum";
import { config } from "../../../../configs/config";
const { Schema } = mongoose;

export interface IAdmin {
  name: string;
  email: string;
  password: string;
  image: object;
  role: Role;
  gender: string;
  dob: Date;
}

const AdminSchema = new Schema({
  name: { type: String, required: true },
  email: { type: String, required: true, unique: true, dropDups: true },
  password: { type: String, required: true },
  image: { type: Object, default: {} },
  role: {
    type: String,
    enum: Role,
  },
  gender: { type: String, required: true },
  dob: { type: Date },
});

AdminSchema.pre("save", async function (next) {
  this.password = await bcrypt.hash(this.password, config.saltRounds);
  next();
});

export const Admin = mongoose.model<IAdmin>("admins", AdminSchema);