윤준석

ADD: checkItems function with checkMamul and push message to client

...@@ -10,7 +10,7 @@ const db = require("../../apis/database"); ...@@ -10,7 +10,7 @@ const db = require("../../apis/database");
10 // database.getAllUsers = async function() 10 // database.getAllUsers = async function()
11 // database.getAllKeywords = async function() 11 // database.getAllKeywords = async function()
12 12
13 -const checkMamul = (client) => { 13 +const multiCheckMamul = (client) => {
14 db.getAllKeywords().then((keywords) => { 14 db.getAllKeywords().then((keywords) => {
15 for (let i = 0, pending = Promise.resolve(); i < keywords.length; i++) { 15 for (let i = 0, pending = Promise.resolve(); i < keywords.length; i++) {
16 pending = db.getUsersByKeyword(keywords[i]).then((userIds) => { 16 pending = db.getUsersByKeyword(keywords[i]).then((userIds) => {
...@@ -22,4 +22,14 @@ const checkMamul = (client) => { ...@@ -22,4 +22,14 @@ const checkMamul = (client) => {
22 }); 22 });
23 }; 23 };
24 24
25 -module.exports = { checkMamul }; 25 +const checkMamul = (client, userId) => {
26 + db.getKeywordsByUserId(userId).then((keywords) => {
27 + for (let i = 0, pending = Promise.resolve(); i< keywords.length; i++) {
28 + pending = marketMultiSearch(keywords[i]).then((res) => {
29 + client.pushMessage(userId, setCarouselMessage(res));
30 + });
31 + };
32 + });
33 +};
34 +
35 +module.exports = { multiCheckMamul, checkMamul };
......
...@@ -18,7 +18,7 @@ const fs = require("fs"); ...@@ -18,7 +18,7 @@ const fs = require("fs");
18 // Cron for Mamul Notification 18 // Cron for Mamul Notification
19 const schedule = require("node-schedule"); 19 const schedule = require("node-schedule");
20 const job = schedule.scheduleJob("0 */1 * * *", () => { 20 const job = schedule.scheduleJob("0 */1 * * *", () => {
21 - checkMamul(client); 21 + multiCheckMamul(client);
22 }); 22 });
23 23
24 // Database APIs 24 // Database APIs
...@@ -39,7 +39,8 @@ const config = { ...@@ -39,7 +39,8 @@ const config = {
39 }; 39 };
40 40
41 // Cron for Mamul Notification 41 // Cron for Mamul Notification
42 -const { checkMamul } = require("./checkMamul/checkMamul"); 42 +const { multiCheckMamul, checkMamul } = require("./checkMamul/checkMamul");
43 +
43 44
44 // Line chat bot client & event 45 // Line chat bot client & event
45 const client = new line.Client(config); 46 const client = new line.Client(config);
...@@ -71,18 +72,7 @@ function handleEvent(event) { ...@@ -71,18 +72,7 @@ function handleEvent(event) {
71 } 72 }
72 } else if (event.postback.data == "checkItems") { 73 } else if (event.postback.data == "checkItems") {
73 return Promise.resolve( 74 return Promise.resolve(
74 - client.replyMessage(event.replyToken, { 75 + checkMamul(client, event.source.userId),
75 - type: "flex",
76 - altText: "등록된 매물",
77 - contents: setFlexMessage(
78 - "daangn",
79 - "RTX 3080",
80 - "1000000",
81 - "https://dnvefa72aowie.cloudfront.net/origin/article/202205/94cdd237258671d5806a70f64ab2b3c7dcd790da0384b394ef5809fe10c08ced.webp?q=95&s=1440x1440&t=inside",
82 - "https://www.daangn.com/articles/403755360",
83 - "채굴X, 흡연X, 반려동물X 입니다.\n직거래 희망하며, 쿨거래시 네고 1만원 가능합니다."
84 - ),
85 - })
86 ); 76 );
87 } 77 }
88 } 78 }
......