윤준석

ADD: delete keyword function with line message api

...@@ -46,14 +46,15 @@ const { multiCheckMamul, checkMamul } = require("./checkMamul/checkMamul"); ...@@ -46,14 +46,15 @@ const { multiCheckMamul, checkMamul } = require("./checkMamul/checkMamul");
46 const client = new line.Client(config); 46 const client = new line.Client(config);
47 47
48 let waitNewMamulList = []; // 매물 키워드 입력 기다리는 목록 48 let waitNewMamulList = []; // 매물 키워드 입력 기다리는 목록
49 +let waitDeleteMamulList = []; // 매물 삭제 키워드 입력 기다리는 목록
49 50
50 function handleEvent(event) { 51 function handleEvent(event) {
51 if (event.type !== "message" || event.message.type !== "text") { 52 if (event.type !== "message" || event.message.type !== "text") {
52 console.log(event); 53 console.log(event);
53 if (event.type == "postback") { 54 if (event.type == "postback") {
54 if (event.postback.data == "newKeyword") { 55 if (event.postback.data == "newKeyword") {
55 - var found = waitNewMamulList.indexOf(event.source.userId); 56 + var foundNew = waitNewMamulList.indexOf(event.source.userId);
56 - if (found == -1) { 57 + if (foundNew == -1) {
57 waitNewMamulList.push(event.source.userId); 58 waitNewMamulList.push(event.source.userId);
58 console.log(`waitNewMamulList Changed : ${waitNewMamulList}`); 59 console.log(`waitNewMamulList Changed : ${waitNewMamulList}`);
59 return Promise.resolve( 60 return Promise.resolve(
...@@ -75,9 +76,17 @@ function handleEvent(event) { ...@@ -75,9 +76,17 @@ function handleEvent(event) {
75 checkMamul(client, event.source.userId), 76 checkMamul(client, event.source.userId),
76 ); 77 );
77 } else if (event.postback.data == "deleteKeyword") { 78 } else if (event.postback.data == "deleteKeyword") {
78 - return Promise.resolve( 79 + var foundDelete = waitDeleteMamulList.indexOf(event.source.userId);
79 - console.log("키워드 삭제") 80 + if (foundDelete == -1) {
80 - ) 81 + waitDeleteMamulList.push(event.source.userId);
82 + console.log(`waitDeleteMamulList Changed : ${waitDeleteMamulList}`);
83 + return Promise.resolve(
84 + client.replyMessage(event.replyToken, {
85 + type: "text",
86 + text: "삭제할 매물 키워드를 알려주세요!",
87 + })
88 + );
89 + }
81 } else if (event.postback.data == "checkKeywords") { 90 } else if (event.postback.data == "checkKeywords") {
82 return Promise.resolve( 91 return Promise.resolve(
83 console.log("키워드 확인") 92 console.log("키워드 확인")
...@@ -87,17 +96,11 @@ function handleEvent(event) { ...@@ -87,17 +96,11 @@ function handleEvent(event) {
87 return Promise.resolve(null); 96 return Promise.resolve(null);
88 } else { 97 } else {
89 console.log(event); 98 console.log(event);
90 - var found = waitNewMamulList.indexOf(event.source.userId); 99 + var foundNew = waitNewMamulList.indexOf(event.source.userId);
91 - if (found == -1) { 100 + if (foundNew != -1) {
92 - return Promise.resolve(
93 - marketMultiSearch(event.message.text).then((res) => {
94 - client.pushMessage(event.source.userId, setCarouselMessage(res));
95 - })
96 - );
97 - } else {
98 // TODO: 서버에 키워드 등록하는 api 101 // TODO: 서버에 키워드 등록하는 api
99 - waitNewMamulList.splice(found, 1); 102 + waitNewMamulList.splice(foundNew, 1);
100 - console.log(waitNewMamulList[found]); 103 + console.log(waitNewMamulList[foundNew]);
101 return Promise.resolve( 104 return Promise.resolve(
102 db.addKeyword(event.message.text, event.source.userId), 105 db.addKeyword(event.message.text, event.source.userId),
103 client.replyMessage(event.replyToken, { 106 client.replyMessage(event.replyToken, {
...@@ -109,6 +112,19 @@ function handleEvent(event) { ...@@ -109,6 +112,19 @@ function handleEvent(event) {
109 }) 112 })
110 ); 113 );
111 } 114 }
115 +
116 + var foundDelete = waitDeleteMamulList.indexOf(event.source.userId);
117 + if (foundDelete != -1) {
118 + waitDeleteMamulList.splice(foundDelete, 1);
119 + console.log(waitDeleteMamulList[foundDelete]);
120 + return Promise.resolve(
121 + db.deleteKeyword(event.source.userId, event.message.text),
122 + client.replyMessage(event.replyToken, {
123 + type: "text",
124 + text: `매물이 삭제되었습니다!\n삭제된 매물: ${event.message.text}`,
125 + })
126 + )
127 + }
112 } 128 }
113 } 129 }
114 130
......