신일섭

db 업데이트중

......@@ -15,12 +15,10 @@ const token = require('../config/key');
const TOKEN = token.token; //사용자 토큰
//----------------------------------------------------------
//----------------low db-----------------------------------
const low = require('lowdb');
const FileSync = require('lowdb/adapters/FileSync')
const adapter = new FileSync('db.json');
const db = low(adapter);
//---------------------------------------------------------
// ------------ db calling modules ---------
var dbcontrol = require('../db/dbcontrol');
// -----------------------------------------
// Gmarket Cart Crawling
async function gmarket_c(user_id, g_id, g_pw){
......@@ -66,6 +64,8 @@ async function gmarket_c(user_id, g_id, g_pw){
console.log(data[index]);
}
//여기에 db에 추가하는 코드 넣기
await browser.close();
......
//----------------low db-----------------------------------
const request = require('request');
const low = require('lowdb');
const FileSync = require('lowdb/adapters/FileSync')
const fs = require('fs');
const TARGET_URL = 'https://api.line.me/v2/bot/message/reply'
const TARGET_URL_2 = 'https://api.line.me/v2/bot/message/push'
const token = require('../config/key');
const TOKEN = token.token; // 사용자 토큰
//var USER_ID = ' '; // LINE 메세지 유저 아이디
//---------------------------------------------------------
// db 초기화
function start_db(USER_ID){
const adapter = new FileSync(USER_ID + '.json');
const db = low(adapter);
db.defaults({cart : []}).write();
}
// 장바구니 동기화
function synchronization(USER_ID, prd_img, prd_name, prd_price, prd_link){
const adapter = new FileSync(USER_ID + '.json');
const db = low(adapter);
db.defaults({cart : []}).write();
// 중복 있는지 검사하는 코드를 if구문에 넣기 (prd_link 기반으로)
// 입력받은 정보를 db에 저장
db.get('cart')
.push({
PRD_IMG : prd_img,
PRD_NAME : prd_name,
PRD_PRICE : prd_price,
PRD_LINK : prd_link
}).write();
}
// db에서 목록 검색 후 삭제
function deleting(USER_ID, prd_link){
const adapter = new FileSync(USER_ID + '.json');
const db = low(adapter);
db.defaults({cart : []}).write();
db.get('cart')
.remove({PRD_LINK : prd_link})
.write(); // prd_link 참조 삭제
}
// db에서 USER_ID 기반 장바구니 조회
function viewing(USER_ID){
const adapter = new FileSync(USER_ID + '.json');
const db = low(adapter);
db.defaults({cart : []}).write();
var datalist = new Array();
datalist = db.get('cart').value(); // [ { } ] 배열속 객체형태로 리턴
//미완성 - 메세지로 내역 push하는 기능 업데이트 요망
}
//================== Just replying specific messages needed ===================================
async function replying(replyToken, sp_message){ // sp_message is message(string) that depends on the situation that user selects
request.post(
{
url: TARGET_URL,
headers: {
'Authorization': `Bearer ${TOKEN}`
},
json: {
"replyToken":replyToken,
"messages":[
{
"type":"text",
"text":sp_message // replying message
}
]
}
},(error, response, body) => {
// console.log(body)
});
}
//================== Just pushing specific messages needed ===================================
async function pushing(USER_ID, sp_message){ //push function
request.post(
{
url: TARGET_URL_2,
headers: {
'Authorization': `Bearer ${TOKEN}`
},
json: {
"to": `${USER_ID}`,
"messages":[
{
"type": "text",
"text": sp_message // replying message
}
]
}
},(error, response, body) => {
//console.log(body)
});
}
//================== 장바구니 목록 전체 출력 ===================================
async function viewall(img_link, msg1, msg2, msg3){ //push function
request.post(
{
url: TARGET_URL_2,
headers: {
'Authorization': `Bearer ${TOKEN}`
},
json: {
"to": `${USER_ID}`,
"messages":[
{
"type":"image",
"originalContentUrl": img_link,
"previewImageUrl": img_link
},
{
"type": "text",
"text": "상품명: " + msg1 // replying message
},
{
"type": "text",
"text": "가격: " + msg2 + " 원" // replying message
},
{
"type": "text",
"text": "링크: " + msg3 // replying message
}
]
}
},(error, response, body) => {
//console.log(body)
});
}
module.exports.start_db = start_db;
module.exports.synchronization = synchronization;
module.exports.deleting = deleting;
module.exports.viewing = viewing;
\ No newline at end of file
//----------------low db-----------------------------------
const low = require('lowdb');
const FileSync = require('lowdb/adapters/FileSync')
const adapter = new FileSync('db.json');
const db = low(adapter);
//---------------------------------------------------------
\ No newline at end of file
......@@ -24,6 +24,10 @@ var method_action = 0; // typing count;
var user_info = new Array(); // 유저 정보 저장용
//------------------------------------------
// ------------ db calling modules ---------
var dbcontrol = require('../db/dbcontrol');
// -----------------------------------------
// ========================================= 쇼핑몰 연결 중계 =========================================
async function shoppingroute(user_message, user_id, replyToken){
......@@ -66,18 +70,14 @@ async function shoppingroute(user_message, user_id, replyToken){
shopping = 2;
}
}
if(user_message == '/장바구니조회')
{
}
if(user_message == '/장바구니추가')
/* if(user_message == '/장바구니조회')
{
}
if(user_message == '/장바구니삭제')
{
}
}*/ //이 기능을 마켓선택기능에 넣는것이 좋을거같음 (db를 공유하기때문에)
}
}
......