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

Update the storing of special units once again

Lee Morgan 5 лет назад
Родитель
Сommit
6a61c30bb2

+ 1 - 0
controllers/ingredientData.js

@@ -36,6 +36,7 @@ module.exports = {
             req.session.error = "MUST BE LOGGED IN TO DO THAT";
             req.session.error = "MUST BE LOGGED IN TO DO THAT";
             return res.redirect("/");
             return res.redirect("/");
         }
         }
+        console.log(req.body);
 
 
         let validation = Validator.ingredient(req.body.ingredient);
         let validation = Validator.ingredient(req.body.ingredient);
         if(validation !== true){
         if(validation !== true){

+ 6 - 1
models/ingredient.js

@@ -8,12 +8,17 @@ const IngredientSchema = new mongoose.Schema({
     },
     },
     category: {
     category: {
         type: String,
         type: String,
-        minlength: 3
+        minlength: 3,
+        required: true
     },
     },
     unitType: {
     unitType: {
         type: String,
         type: String,
         required: true
         required: true
     },
     },
+    specialUnit: {
+        type: String,
+        required: false
+    },
     unitSize:{
     unitSize:{
         type: Number,
         type: Number,
         required: false
         required: false

+ 7 - 3
views/dashboardPage/bundle.js

@@ -1,13 +1,14 @@
 (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
 (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
 class Ingredient{
 class Ingredient{
-    constructor(id, name, category, unitType, unit, parent, unitSize = undefined){
+    constructor(id, name, category, unitType, unit, parent, specialUnit = undefined, unitSize = undefined){
         this.id = id;
         this.id = id;
         this.name = name;
         this.name = name;
         this.category = category;
         this.category = category;
         this.unitType = unitType;
         this.unitType = unitType;
         this.unit = unit;
         this.unit = unit;
         this.parent = parent;
         this.parent = parent;
-        if(unitSize){
+        if(specialUnit){
+            this.specialUnit = specialUnit;
             this.unitSize = unitSize;
             this.unitSize = unitSize;
         }
         }
         
         
@@ -78,6 +79,7 @@ class Merchant{
                     oldMerchant.inventory[i].ingredient.unitType,
                     oldMerchant.inventory[i].ingredient.unitType,
                     oldMerchant.inventory[i].defaultUnit,
                     oldMerchant.inventory[i].defaultUnit,
                     this,
                     this,
+                    oldMerchant.inventory[i].ingredient.specialUnit,
                     oldMerchant.inventory[i].ingredient.unitSize
                     oldMerchant.inventory[i].ingredient.unitSize
                 ),
                 ),
                 quantity: oldMerchant.inventory[i].quantity
                 quantity: oldMerchant.inventory[i].quantity
@@ -1455,7 +1457,6 @@ let ingredientDetails = {
 
 
     display: function(ingredient){
     display: function(ingredient){
         this.ingredient = ingredient;
         this.ingredient = ingredient;
-        console.log(ingredient);
 
 
         document.getElementById("ingredientDetailsCategory").innerText = ingredient.ingredient.category;
         document.getElementById("ingredientDetailsCategory").innerText = ingredient.ingredient.category;
 
 
@@ -1885,6 +1886,7 @@ let newIngredient = {
             defaultUnit: unit
             defaultUnit: unit
         }
         }
 
 
+        //Change the ingredient if it is a special unit type (ie "bottle")
         if(unit === "bottle"){
         if(unit === "bottle"){
             const bottleUnit = document.getElementById("bottleUnits").value;
             const bottleUnit = document.getElementById("bottleUnits").value;
             const bottleSize = controller.convertToMain(bottleUnit, document.getElementById("bottleSize").value);
             const bottleSize = controller.convertToMain(bottleUnit, document.getElementById("bottleSize").value);
@@ -1892,6 +1894,7 @@ let newIngredient = {
             newIngredient.ingredient.unitType = "volume";
             newIngredient.ingredient.unitType = "volume";
             newIngredient.ingredient.unitSize = bottleSize;
             newIngredient.ingredient.unitSize = bottleSize;
             newIngredient.defaultUnit = bottleUnit;
             newIngredient.defaultUnit = bottleUnit;
+            newIngredient.ingredient.specialUnit = unit;
         }
         }
     
     
         let loader = document.getElementById("loaderContainer");
         let loader = document.getElementById("loaderContainer");
@@ -1917,6 +1920,7 @@ let newIngredient = {
                             response.ingredient.unitType,
                             response.ingredient.unitType,
                             response.defaultUnit,
                             response.defaultUnit,
                             merchant,
                             merchant,
+                            response.ingredient.specialUnit,
                             response.ingredient.unitSize
                             response.ingredient.unitSize
                         ),
                         ),
                         quantity: response.quantity
                         quantity: response.quantity

+ 3 - 2
views/dashboardPage/js/Ingredient.js

@@ -1,12 +1,13 @@
 class Ingredient{
 class Ingredient{
-    constructor(id, name, category, unitType, unit, parent, unitSize = undefined){
+    constructor(id, name, category, unitType, unit, parent, specialUnit = undefined, unitSize = undefined){
         this.id = id;
         this.id = id;
         this.name = name;
         this.name = name;
         this.category = category;
         this.category = category;
         this.unitType = unitType;
         this.unitType = unitType;
         this.unit = unit;
         this.unit = unit;
         this.parent = parent;
         this.parent = parent;
-        if(unitSize){
+        if(specialUnit){
+            this.specialUnit = specialUnit;
             this.unitSize = unitSize;
             this.unitSize = unitSize;
         }
         }
         
         

+ 1 - 0
views/dashboardPage/js/Merchant.js

@@ -27,6 +27,7 @@ class Merchant{
                     oldMerchant.inventory[i].ingredient.unitType,
                     oldMerchant.inventory[i].ingredient.unitType,
                     oldMerchant.inventory[i].defaultUnit,
                     oldMerchant.inventory[i].defaultUnit,
                     this,
                     this,
+                    oldMerchant.inventory[i].ingredient.specialUnit,
                     oldMerchant.inventory[i].ingredient.unitSize
                     oldMerchant.inventory[i].ingredient.unitSize
                 ),
                 ),
                 quantity: oldMerchant.inventory[i].quantity
                 quantity: oldMerchant.inventory[i].quantity

+ 0 - 1
views/dashboardPage/js/ingredientDetails.js

@@ -4,7 +4,6 @@ let ingredientDetails = {
 
 
     display: function(ingredient){
     display: function(ingredient){
         this.ingredient = ingredient;
         this.ingredient = ingredient;
-        console.log(ingredient);
 
 
         document.getElementById("ingredientDetailsCategory").innerText = ingredient.ingredient.category;
         document.getElementById("ingredientDetailsCategory").innerText = ingredient.ingredient.category;
 
 

+ 3 - 0
views/dashboardPage/js/newIngredient.js

@@ -38,6 +38,7 @@ let newIngredient = {
             defaultUnit: unit
             defaultUnit: unit
         }
         }
 
 
+        //Change the ingredient if it is a special unit type (ie "bottle")
         if(unit === "bottle"){
         if(unit === "bottle"){
             const bottleUnit = document.getElementById("bottleUnits").value;
             const bottleUnit = document.getElementById("bottleUnits").value;
             const bottleSize = controller.convertToMain(bottleUnit, document.getElementById("bottleSize").value);
             const bottleSize = controller.convertToMain(bottleUnit, document.getElementById("bottleSize").value);
@@ -45,6 +46,7 @@ let newIngredient = {
             newIngredient.ingredient.unitType = "volume";
             newIngredient.ingredient.unitType = "volume";
             newIngredient.ingredient.unitSize = bottleSize;
             newIngredient.ingredient.unitSize = bottleSize;
             newIngredient.defaultUnit = bottleUnit;
             newIngredient.defaultUnit = bottleUnit;
+            newIngredient.ingredient.specialUnit = unit;
         }
         }
     
     
         let loader = document.getElementById("loaderContainer");
         let loader = document.getElementById("loaderContainer");
@@ -70,6 +72,7 @@ let newIngredient = {
                             response.ingredient.unitType,
                             response.ingredient.unitType,
                             response.defaultUnit,
                             response.defaultUnit,
                             merchant,
                             merchant,
+                            response.ingredient.specialUnit,
                             response.ingredient.unitSize
                             response.ingredient.unitSize
                         ),
                         ),
                         quantity: response.quantity
                         quantity: response.quantity