-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnodeHandyMan.js
More file actions
119 lines (111 loc) · 2.97 KB
/
nodeHandyMan.js
File metadata and controls
119 lines (111 loc) · 2.97 KB
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
function getWork(req,res,con){
var value=req.query;
var id=value.handyman_id;
var sql="select complaint_id,c.student_id,subject,gender,date,type,catagory,cost,description,time_slot,descriptionFull,email,phone_no,room_no,name from complaint_info as c,student_info as s where handyman_id="+id+" and status<2 and c.student_id=s.student_id order by complaint_id;"
con.query(sql,function(err,result){
if(err!=null){
res.end(String(err));
return;
}
res.end(JSON.stringify(result));
return;
});
}
function complaintSolved(req,res,con){
var value=req.query;
var complaint_id=value.complaint_id;
var otp=value.otp;
var handyman_id=value.handyman_id;
var sql="update complaint_info set status=2 where complaint_id="+complaint_id+" and otp="+otp;
con.query(sql,function(err,result){
if(err!=null){
res.end("false");
return;
}
if(result.affectedRows==0){
res.end("Wrong OTP");
return;
}
if(result.changedRows==0){
res.end("Reload");
return;
}
sql="update handyman_info set solved=solved+1,today=today+1 where handyman_id="+handyman_id;
con.query(sql,function(err,result){
if(err!=null){
res.end("false");
return;
}
else{
res.end("true");
}
});
});
}
function complaintHistory(req,res,con){
var handyman_id=req.query.handyman_id;
var type=req.query.type;
var status="(1,2,3)";
if(type=="Solved"){
status="(2,3)";
}
if(type=="Unsolved"){
status="(1)";
}
//console.log(type);
var sql="select * from complaint_info c,student_info s where handyman_id=? and status in "+status+" and c.student_id=s.student_id order by complaint_id";
con.query(sql,[[handyman_id]],function(err,result){
if(err){
res.end(JSON.stringify(err));
}
res.end(JSON.stringify(result));
})
}
function changeHandymanPassword(req,res,con){
var handyman_id=req.query.handyman_id;
var old_pass=req.query.old_Pass;
var new_pass=req.query.new_Pass;
var sql="update handyman_info set password=? where handyman_id=? and password=?";
con.query(sql,[new_pass,handyman_id,old_pass],function(err,result){
if(err!=null){
console.log(err);
res.end("false");
}
else if(result.affectedRows==1)
res.end("true");
else
res.end("old");
})
};
function changeHandymanPhone(req,res,con){
var handyman_id=req.query.handyman_id;
var phone=req.query.new_phone;
var sql="update handyman_info set phone_no=? where handyman_id=?";
con.query(sql,[phone,handyman_id],function(err,result){
if(err!=null){
console.log(err);
res.end("false");
}
else if(result.affectedRows==1)
res.end("true");
//console.log(result);
//console.log(req.query);
})
};
module.exports={
getWork:function(req,res,con){
getWork(req,res,con);
},
complaintSolved:function(req,res,con){
complaintSolved(req,res,con);
},
complaintHistory:function(req,res,con){
complaintHistory(req,res,con);
},
changeHandymanPassword:function(req,res,con){
changeHandymanPassword(req,res,con);
},
changeHandymanPhone:function(req,res,con){
changeHandymanPhone(req,res,con);
}
}