Просмотр исходного кода

Add price to recipes for clover users

Lee Morgan 6 лет назад
Родитель
Сommit
1d5780474e
5 измененных файлов с 30 добавлено и 2 удалено
  1. 10 1
      controllers/home.js
  2. 1 1
      models/merchant.js
  3. 4 0
      models/recipe.js
  4. 14 0
      models/transactions.js
  5. 1 0
      views/merchantSetupPage/createRecipes.js

+ 10 - 1
controllers/home.js

@@ -25,7 +25,9 @@ module.exports = {
                     axios.get(`https://apisandbox.dev.clover.com/v3/merchants/${merchant.posId}/orders?filter=clientCreatedTime>=${merchant.lastUpdatedTime}&expand=lineItems&access_token=${token}`)
                         .then((result)=>{
                             for(let order of result.data.elements){
+                                console.log(order);
                                 for(let item of order.lineItems.elements){
+                                    console.log(item);
                                     let recipe = merchant.recipes.find(r => r.posId === item.item.id);
                                     if(recipe){
                                         for(let ingredient of recipe.ingredients){
@@ -44,7 +46,9 @@ module.exports = {
 
                             merchant.save()
                                 .then((updatedMerchant)=>{
-                                    return res.render("inventoryPage/inventory", {merchant: updatedMerchant});
+                                    res.render("inventoryPage/inventory", {merchant: updatedMerchant});
+                                    // this.storeTransactions(result);
+                                    return;
                                 })
                                 .catch((err)=>{
                                     console.log(err);
@@ -581,5 +585,10 @@ module.exports = {
                 console.log(err);
                 return res.redirect("/");
             });
+    },
+
+    //Helper functions
+    storeTransactions: function(data){
+        console.log(data);
     }
 }

+ 1 - 1
models/merchant.js

@@ -41,7 +41,7 @@ const MerchantSchema = new mongoose.Schema({
     }],
     recipes: [{
         type: mongoose.Schema.Types.ObjectId,
-        ref: "Recipe",
+        ref: "Recipe"
     }]
 });
 

+ 4 - 0
models/recipe.js

@@ -11,6 +11,10 @@ const RecipeSchema = new mongoose.Schema({
         type: String,
         required: true,
     },
+    price: {
+        type: Number,
+        min: 0
+    },
     ingredients: [{
         ingredient: {
             type: mongoose.Schema.Types.ObjectId,

+ 14 - 0
models/transactions.js

@@ -0,0 +1,14 @@
+const mongoose = require("mongoose");
+
+const TransactionSchema = new mongoose.Schema({
+    date: {
+        type: Date,
+        required: [true, "Must provide date and time transacted"]
+    },
+    recipes: [{
+        type: mongoose.Schema.Types.ObjectId,
+        ref: "Recipe"
+    }]
+});
+
+module.exports = mongoose.model("Transaction", TransactionSchema);

+ 1 - 0
views/merchantSetupPage/createRecipes.js

@@ -12,6 +12,7 @@ let createRecipesObj = {
                 controller.data.recipes.push({
                     name: recipe.name,
                     posId: recipe.id,
+                    price: recipe.price,
                     ingredients: [],
                 });
             }