File size: 958 Bytes
d50360d
 
433085e
a99a515
 
d50360d
433085e
 
 
 
 
 
 
 
a99a515
98d83e7
433085e
 
 
 
 
 
 
 
a99a515
 
 
 
d50360d
 
433085e
 
 
d50360d
 
484fdbc
 
 
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
37
38
39
import mongoose from "mongoose";
import bcrypt from "bcrypt";
import { config } from "../../../../configs/config";
import { Role } from "@common/enums/role.enum";

const { Schema } = mongoose;

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

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: {} },
  gender: { type: String, required: true },
  dob: { type: Date },
  role: {
    type: String,
    enum: Role
  },
});

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

export type AdminDocument = mongoose.Document & IAdmin;

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