-
Notifications
You must be signed in to change notification settings - Fork 1
/
admin.ts
61 lines (55 loc) · 1.12 KB
/
admin.ts
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// admin.model.ts
import { Schema, model } from "mongoose";
import { NewAdminParams } from "../controllers/admin/types";
// Create the interface
interface IAdmin {
firstName: string;
lastName: string;
email: string;
password: string;
contact: string;
isActive: boolean;
}
// Create the schema
const AdminSchema = new Schema<IAdmin>(
{
firstName: {
type: String,
required: true,
},
lastName: {
type: String,
required: true,
},
email: {
type: String,
required: true,
},
password: {
type: String,
},
contact: {
type: String,
required: true,
},
isActive: {
type: Boolean,
default: false,
},
},
{
timestamps: {
createdAt: "createdAt",
updatedAt: "updatedAt",
},
}
);
// Create and export admin model
export const Admin = model<IAdmin>("Admin", AdminSchema);
export const getAdminsByEmail= async(email:string):Promise<IAdmin>=>{
return Admin.findOne({email})
}
export const insertAdmin =async (params:NewAdminParams) => {
const newAdmin = new Admin({ ...params});
return newAdmin.save();
}