-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadmincontroller.js
65 lines (52 loc) · 1.87 KB
/
admincontroller.js
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
62
63
64
65
const adminModel = require('../model/adminmodel')
const bcrypt = require('bcrypt')
const userModel = require('../model/usermodel')
module.exports = {
adminlogin: (adminlogindata) => {
return new Promise(async (resolve,reject) => {
let response = {
status: false,
adminnotfound: false
}
let admin = await adminModel.findOne({email: adminlogindata.email})
console.log('email')
if(admin) {
bcrypt.compare(adminlogindata.password, admin.password, (err,valid) => {
if(valid) {
response.status = true
response.admin = admin
response.email = admin.email
console.log(response.email)
resolve(response)
console.log('success')
}else{
response.adminnotfound=true
resolve(response);
console.log('error bcrypting',err)
}
})
}else{
response.adminnotfound = true
console.log('failed');
resolve(response)
}
})
},
//...................... Block User........................//
block_user: (id) => {
return new Promise(async (resolve, reject) => {
let user = await userModel.findById({ _id: Object(id) })
user.status = true
await userModel.updateOne({ _id: Object(id) }, user)
resolve('got it')
})
},
active_user: (id) => {
return new Promise(async (resolve, reject) => {
let user = await userModel.findById({ _id: Object(id) })
user.status = false
await userModel.updateOne({ _id: Object(id) }, user)
resolve('its done')
})
}
}