Procházet zdrojové kódy

Update name "purchase" to "order"

Lee Morgan před 6 roky
rodič
revize
b0855809e2

+ 15 - 15
controllers/otherData.js

@@ -2,14 +2,14 @@ const bcrypt = require("bcryptjs");
 const axios = require("axios");
 
 const Merchant = require("../models/merchant");
-const Purchase = require("../models/purchase");
+const Order = require("../models/order");
 const Transaction = require("../models/transaction");
 
 module.exports = {
-    //POST - Creates a new purchase for a merchant
+    //POST - Creates a new order for a merchant
     //Inputs:
-    //  req.body: list of purchases (ingredient id and quantity)
-    createPurchase: function(req, res){
+    //  req.body: list of orders (ingredient id and quantity)
+    createOrder: function(req, res){
         if(!req.session.user){
             req.session.error = "Must be logged in to do that";
             return res.redirect("/");
@@ -17,9 +17,9 @@ module.exports = {
 
         Merchant.findOne({_id: req.session.user})
             .then((merchant)=>{
-                for(let purchase of req.body){
-                    let merchantIngredient = merchant.inventory.find(i => i.ingredient._id.toString() === purchase.ingredient);
-                    merchantIngredient.quantity += Number(purchase.quantity);
+                for(let order of req.body){
+                    let merchantIngredient = merchant.inventory.find(i => i.ingredient._id.toString() === order.ingredient);
+                    merchantIngredient.quantity += Number(order.quantity);
                 }
                 
                 merchant.save()
@@ -34,12 +34,12 @@ module.exports = {
                 return res.json("Error: Unable to retrieve user data");
             });
 
-            let purchase = new Purchase({
+            let order = new Order({
                 merchant: req.session.user,
                 date: Date.now(),
                 ingredients: req.body
             });
-            purchase.save().catch((err)=>{});
+            order.save().catch((err)=>{});
     },
 
     //POST - logs the user in
@@ -132,13 +132,13 @@ module.exports = {
             });
     },
 
-    //POST - Gets transactions and purchases between 2 dates for a merchant
+    //POST - Gets transactions and orders between 2 dates for a merchant
     //Inputs:
     //  req.body.from = start date
     //  req.body.to = end date
     //Returns:
     //  transactions = list of transactions between the dates provided
-    //  purchases = list of purchases between the dates provided
+    //  orders = list of orders between the dates provided
     getData: function(req, res){
         if(!req.session.user){
             req.session.error = "Must be logged in to do that";
@@ -159,11 +159,11 @@ module.exports = {
             }));
 
             promiseList.push(new Promise((resolve, reject)=>{
-                Purchase.find({merchant: req.session.user, date: {$gte: req.body.dates[i], $lt: req.body.dates[i+1]}},
+                Order.find({merchant: req.session.user, date: {$gte: req.body.dates[i], $lt: req.body.dates[i+1]}},
                     {date: 1, ingredients: 1, _id: 0},
                     {sort: {date: 1}})
-                    .then((purchases)=>{
-                        resolve(purchases);
+                    .then((orders)=>{
+                        resolve(orders);
                     })
                     .catch((err)=>{})
             }));
@@ -176,7 +176,7 @@ module.exports = {
                 for(let i = 0; i < response.length; i+=2){
                     newList.push({
                         transactions: response[i],
-                        purchases: response[i+1]
+                        orders: response[i+1]
                     });
                 }
 

+ 7 - 7
controllers/renderer.js

@@ -3,7 +3,7 @@ const ObjectId = require("mongoose").Types.ObjectId;
 
 const Merchant = require("../models/merchant");
 const Transaction = require("../models/transaction");
-const Purchase = require("../models/purchase");
+const Order = require("../models/order");
 
 module.exports = {
     //GET - Shows the public landing page
@@ -203,22 +203,22 @@ module.exports = {
                 .catch((err)=>{});
         });
 
-        let purchasePromise = new Promise((resolve, reject)=>{
-            Purchase.find({merchant: req.session.user, date: {$gte: firstDay, $lt: lastDay}},
+        let orderPromise = new Promise((resolve, reject)=>{
+            Order.find({merchant: req.session.user, date: {$gte: firstDay, $lt: lastDay}},
                 {date: 1, ingredients: 1, _id: 0},
                 {sort: {date: 1}})
-                .then((purchases)=>{
-                    resolve(purchases);
+                .then((orders)=>{
+                    resolve(orders);
                 })
                 .catch((err)=>{});
         });
 
-        Promise.all([merchTransPromise, purchasePromise])
+        Promise.all([merchTransPromise, orderPromise])
             .then((response)=>{
                 let data = {
                     merchant: response[0].merchant,
                     transactions: response[0].transactions,
-                    purchases: response[1],
+                    orders: response[1],
                     dates: [firstDay, lastDay]
                 }
 

+ 6 - 7
controllers/transactionData.js

@@ -1,5 +1,5 @@
 const Transaction = require("../models/transaction");
-const Purchase = require("../models/purchase");
+const Order = require("../models/order");
 const Merchant = require("../models/merchant");
 
 module.exports = {
@@ -37,18 +37,18 @@ module.exports = {
             });
     },
 
-    getPurchases: function(req, res){
+    getOrders: function(req, res){
         if(!req.session.user){
             req.session.error = "You must be logged in to view that page";
             return res.redirect("/");
         }
 
-        Purchase.find({merchant: req.session.user})
-            .then((purchases)=>{
-                return res.json(purchases);
+        Order.find({merchant: req.session.user})
+            .then((orders)=>{
+                return res.json(orders);
             })
             .catch((err)=>{
-                return res.json("Error: could not retrieve purchases data");
+                return res.json("Error: could not retrieve order data");
             })
     },
 
@@ -116,7 +116,6 @@ module.exports = {
         function randomDate() {
             let now = new Date();
             let start = new Date();
-            // start.setDate(now.getDate() - 10);
             start.setFullYear(now.getFullYear() - 1);
             return new Date(start.getTime() + Math.random() * (now.getTime() - start.getTime()));
         }

+ 2 - 2
models/purchase.js → models/order.js

@@ -1,6 +1,6 @@
 const mongoose = require("mongoose");
 
-const PurchaseSchema = new mongoose.Schema({
+const OrderSchema = new mongoose.Schema({
     merchant: {
         type: mongoose.Schema.Types.ObjectId,
         ref: "Merchant",
@@ -25,4 +25,4 @@ const PurchaseSchema = new mongoose.Schema({
     }]
 });
 
-module.exports = mongoose.model("Purchase", PurchaseSchema);
+module.exports = mongoose.model("Order", OrderSchema);

+ 2 - 2
routes.js

@@ -35,7 +35,7 @@ module.exports = function(app){
     app.post("/recipe/create", recipeData.createRecipe);
 
     //Other
-    app.post("/purchases/create", otherData.createPurchase);
+    app.post("/purchases/create", otherData.createOrder);
     app.post("/login", otherData.login);
     app.get("/logout", otherData.logout);
     app.get("/cloverlogin", otherData.cloverRedirect);
@@ -46,7 +46,7 @@ module.exports = function(app){
 
     //Transactions
     app.post("/transactions", transactionData.getTransactions);
-    app.get("/purchases", transactionData.getPurchases);
+    app.get("/purchases", transactionData.getOrders);
     app.post("/transactions/create", transactionData.createTransaction);  //Creates transaction for non-pos merchant
     app.get("/populatesometransactions", transactionData.populate);
 }

+ 2 - 1
views/dashboardPage/dashboard.ejs

@@ -82,7 +82,7 @@
             </div>
 
             <div id="ordersStrand" class="strand">
-                <h1>Orders Strand</h1>
+                <h1>Orders</h1>
             </div>
         </div>
 
@@ -101,6 +101,7 @@
         <script src="/dashboardPage/ingredients.js"></script>
         <script src="/dashboardPage/recipeBook.js"></script>
         <script src="/dashboardPage/controller.js"></script>
+        <script src="/dashboardPage/orders.js"></script>
         <script src="../shared/validation.js"></script>
     </body>
 </html>

+ 5 - 0
views/dashboardPage/orders.js

@@ -0,0 +1,5 @@
+window.ordersStrandObj = {
+    display: function(){
+        console.log("displaying orders");
+    }
+}