Spaces:
Running
Running
File size: 807 Bytes
d50360d 98d83e7 d50360d 98d83e7 d50360d 98d83e7 d50360d |
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 mongoose from "mongoose";
import bcrypt from "bcrypt";
export const saltrounds = 5;
const { Schema } = mongoose;
enum Role {
SUPER_ADMIN= "superAdmin",
ADMIN= "admin"
}
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: {} },
permission: { type: Object, required: true },
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, saltrounds);
next();
});
export const adminModel = mongoose.model("admins", adminSchema);
|