I have task to complete with nodejs and oracle using the following tables.
TABLE 1:
[{ "storeid" : 3,"location" : "Hyderabad", "contactdetails" : "Ameerpet" }, { "storeid" : 4, "location" : "Vizag", "contactdetails" : "RK Beach" }]
TABLE 2:
[{ "storeid":4, "startDate" : "2017-04-03", "endDate":"2017-04-05", "reason": "snow", "type": "Rx" },{ "storeid":4, "startDate" : "2017-04-03", "endDate":"2017-04-04", "reason": "snow", "type":"store" },{ "storeid":4, "startDate" : "2017-04-28", "endDate":"2017-04-28", "reason": "snow", "type": "Rx" },{ "storeid":4, "startDate" : "2017-04-28", "endDate":"2017-04-28", "reason": "snow", "type":"store" },{ "storeid":3, "startDate" : "2017-04-03", "endDate":"2017-04-05", "reason": "snow", "type": "Rx" },{ "storeid":3, "startDate" : "2017-04-03", "endDate":"2017-04-04", "reason": "snow", "type":"store" },{ "storeid":3, "startDate" : "2017-04-28", "endDate":"2017-04-28", "reason": "snow", "type": "Rx" },{ "storeid":3, "startDate" : "2017-04-28", "endDate":"2017-04-28", "reason": "snow", "type":"store" }]
Expected Output:
[{ "storeid" : 3,"location" : "Hyderabad", "contactdetails" : "Ameerpet","pastClose":[{
"storeid":3, "startDate" : "2017-04-03","type": "Rx"},{
"storeid":3, "startDate" : "2017-04-03","type":"store"}], "futureClose" : [{
"storeid":3, "startDate" : "2017-04-28","type": "Rx"},{
"storeid":3, "startDate" : "2017-04-28","type":"store"}]
},{ "storeid" : 4, "location" : "Vizag", "contactdetails" : "RK Beach", "pastClose":[{
"storeid":4, "startDate" : "2017-04-03","type": "Rx"},{
"storeid":4, "startDate" : "2017-04-03","type":"store"}],"futureClose" : [{
"storeid":4, "startDate" : "2017-04-28","type": "Rx"},{
"storeid":4, "startDate" : "2017-04-28","type":"store"}]
}]
Code Snippet:
var store = [];
table1.find({}, function(err, tab1results){
async.each(tab1results, function(tab1, callback){
table2.find(tab1.storeid, function(err, tab2records){
tab1.pastClose = tab2records;
store.push(tab1);
if(tab1results.length == i){
callback(store);
}
})
}, function(store){
console.log(store);
})
})
I have got two problems while working with above Code.
1) Oracle connection error, while iterating on second table based on storeIds from second table.
2) Condition missing
a) futureClose = startDate > currentdata
b) pastClose = startDate < currentdata
Please help me to code, for a single query to fetch.
via Ayyappa A
No comments:
Post a Comment