-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathusercontroller.js
87 lines (77 loc) · 2.74 KB
/
usercontroller.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
const userModel = require('../model/usermodel')
const bcrypt = require('bcrypt')
module.exports = {
userlogin: (logindata) => {
return new Promise(async (resolve, reject) => {
let response = {
status: false,
usernotfound: false
}
let user = await userModel.findOne({ email: logindata.email })
console.log('emai')
console.log(user);
if (user) {
bcrypt.compare(logindata.password, user.password, (err, valid) => {
if (valid) {
response.status = true
response.user = user
response.email = user.email
console.log(response.email)
resolve(response)
console.log('success')
} else {
response.usernotfound = true
response.status = false
resolve(response);
console.log('error bcrypting', err)
}
})
} else {
response.usernotfound = true
console.log('failed');
response.status = false
resolve(response)
}
})
},
getUserData: (userid) => {
console.log(userid, ';this is productid')
return new Promise((res, rej) => {
userModel.findOne({ _id: userid }).lean().then((data) => {
console.log(data, 'this is data');
res(data)
})
})
},
getAllUserData: () => {
return new Promise((res, rej) => {
userModel.find().lean().then((data) => {
console.log(data, 'this is data');
res(data)
})
})
},
allusers:()=>{
return new Promise((resolve,reject)=>{
try{
let response = {}
userModel.find().lean().then((users)=>{
let totaluser = users.length;
userModel.find({status:true}).lean().then((blocked)=>{
blockeduser = blocked.length
userModel.find({status:false}).lean().then((active)=>{
activeuser = active.length
response.totalusers = totaluser;
response.activeusers = activeuser
response.blockedusers = blockeduser
resolve(response)
})
})
})
}
catch(error){
reject(error)
}
})
}
}