유명현

ADD: cron message + clean-up unessential message

......@@ -10,12 +10,6 @@ sequelize
.sync({ force: false })
.then(() => {
console.log("database connection complete");
database.addKeyword("rtx3060", "junseok");
database.getKeywordsByUserId("junseok");
database.deleteKeyword("phobyjun", "rtx3080");
database.getAllUsers();
database.getUsersByKeyword("rtx3060");
database.getAllKeywords();
})
.catch((err) => {
console.log("database connection failed");
......
const { marketMultiSearch } = require("../search/marketSearch");
const setCarouselMessage = require("../message/setCarouselMessage");
// Database APIs
const db = require("../../apis/database");
// API List
// database.addKeyword = async function(keyword, userId)
// database.deleteKeyword = async function(userId, keyword)
// database.getKeywordsByUserId = async function(userId)
// database.getUsersByKeyword = async function(keyword)
// database.getAllUsers = async function()
// database.getAllKeywords = async function()
const checkMamul = (client) => {
db.getAllKeywords().then((keywords) => {
for (let i = 0, pending = Promise.resolve(); i < keywords.length; i++) {
pending = db.getUsersByKeyword(keywords[i]).then((userIds) => {
marketMultiSearch(keywords[i]).then((res) => {
client.multicast(userIds, [setCarouselMessage(res)]);
});
});
}
});
};
module.exports = { checkMamul };
......@@ -15,6 +15,12 @@ const { marketMultiSearch } = require("./search/marketSearch");
// File search - Will be deleted (Unused)
const fs = require("fs");
// Cron for Mamul Notification
const schedule = require("node-schedule");
const job = schedule.scheduleJob("0 */1 * * *", () => {
checkMamul(client);
});
// Database APIs
const db = require("../apis/database");
// API List
......@@ -32,6 +38,10 @@ const config = {
channelSecret: process.env.channelSecret,
};
// Cron for Mamul Notification
const { checkMamul } = require("./checkMamul/checkMamul");
// Line chat bot client & event
const client = new line.Client(config);
let waitNewMamulList = []; // 매물 키워드 입력 기다리는 목록
......
This diff is collapsed. Click to expand it.
......@@ -20,6 +20,7 @@
"dotenv": "^16.0.1",
"express": "^4.18.1",
"mysql2": "^2.3.3",
"node-schedule": "^2.1.0",
"nodemon": "^2.0.16",
"sequelize": "^6.20.0"
}
......