toror33

연락처 검색

...@@ -42,7 +42,37 @@ contact_search : 연락처 검색 모듈 ...@@ -42,7 +42,37 @@ contact_search : 연락처 검색 모듈
42 input : 사용자가 이름, 전화번호, 이메일 중 하나를 검색 42 input : 사용자가 이름, 전화번호, 이메일 중 하나를 검색
43 output : 검색을 요청한 데이터에 부합하는 연락처를 찾았다면 출력 43 output : 검색을 요청한 데이터에 부합하는 연락처를 찾았다면 출력
44 */ 44 */
45 -router.get('/contact_search', function(req, res, next) { 45 +router.post('/contact_search', function(req, res, next) {
46 + console.log("req.query",req.query);
47 + var user_id = req.query.id;
48 + var type = req.query.type;
49 + var info = "";
50 + if(type == "name")
51 + {
52 + info = req.query.name;
53 + var sqlquery = "SELECT * FROM contact WHERE user_id = ? and name = ?";
54 + }
55 + else if(type == "phone")
56 + {
57 + info = req.query.phone;
58 + var sqlquery = "SELECT * FROM contact WHERE user_id = ? and phone = ?";
59 + }
60 + else if(type == "email")
61 + {
62 + info = req.query.email;
63 + var sqlquery = "SELECT * FROM contact WHERE user_id = ? and email = ?";
64 + }
65 + console.log(sqlquery);
66 + connection.query(sqlquery, [user_id,info], function (err, rows) {
67 + if (err) {
68 + console.log("search contact failed");
69 + throw err;
70 + } else {
71 + console.log(rows);
72 + res.status(200).send({contact_list : rows});
73 + }
74 +
75 + });
46 }); 76 });
47 77
48 /* 78 /*
......