|
@@ -33,7 +33,6 @@ module.exports = {
|
|
|
req.session.error = "You must logged in to view that page";
|
|
req.session.error = "You must logged in to view that page";
|
|
|
return res.redirect("/");
|
|
return res.redirect("/");
|
|
|
}
|
|
}
|
|
|
- console.log("Session good, start of function");
|
|
|
|
|
|
|
|
|
|
Merchant.findOne({_id: req.session.user})
|
|
Merchant.findOne({_id: req.session.user})
|
|
|
.populate("inventory.ingredient")
|
|
.populate("inventory.ingredient")
|
|
@@ -46,11 +45,9 @@ module.exports = {
|
|
|
}
|
|
}
|
|
|
})
|
|
})
|
|
|
.then((merchant)=>{
|
|
.then((merchant)=>{
|
|
|
- console.log("Got the merchant");
|
|
|
|
|
if(merchant.pos === "clover"){
|
|
if(merchant.pos === "clover"){
|
|
|
axios.get(`https://apisandbox.dev.clover.com/v3/merchants/${merchant.posId}/orders?filter=clientCreatedTime>=${merchant.lastUpdatedTime}&expand=lineItems&access_token=${token}`)
|
|
axios.get(`https://apisandbox.dev.clover.com/v3/merchants/${merchant.posId}/orders?filter=clientCreatedTime>=${merchant.lastUpdatedTime}&expand=lineItems&access_token=${token}`)
|
|
|
.then((result)=>{
|
|
.then((result)=>{
|
|
|
- console.log("axios to clover returned");
|
|
|
|
|
let transactions = [];
|
|
let transactions = [];
|
|
|
for(let order of result.data.elements){
|
|
for(let order of result.data.elements){
|
|
|
let newTransaction = new Transaction({
|
|
let newTransaction = new Transaction({
|
|
@@ -78,14 +75,12 @@ module.exports = {
|
|
|
transactions.push(newTransaction);
|
|
transactions.push(newTransaction);
|
|
|
}
|
|
}
|
|
|
merchant.lastUpdatedTime = Date.now();
|
|
merchant.lastUpdatedTime = Date.now();
|
|
|
- console.log("Did all calculations on Clover data");
|
|
|
|
|
|
|
|
|
|
merchant.save()
|
|
merchant.save()
|
|
|
.then((updatedMerchant)=>{
|
|
.then((updatedMerchant)=>{
|
|
|
merchant.password = undefined;
|
|
merchant.password = undefined;
|
|
|
res.render("inventoryPage/inventory", {merchant: updatedMerchant, error: undefined});
|
|
res.render("inventoryPage/inventory", {merchant: updatedMerchant, error: undefined});
|
|
|
Transaction.create(transactions);
|
|
Transaction.create(transactions);
|
|
|
- console.log("Saved merchant, render page");
|
|
|
|
|
return;
|
|
return;
|
|
|
})
|
|
})
|
|
|
.catch((err)=>{
|
|
.catch((err)=>{
|