Explorar o código

Update errors for transaction model.
Fix error handling for transaction spreadsheet submission.

Lee Morgan %!s(int64=5) %!d(string=hai) anos
pai
achega
f193bb5c47

+ 3 - 1
controllers/recipeData.js

@@ -415,7 +415,9 @@ module.exports = {
                 if(typeof(err) === "string"){
                     return res.json(err);
                 }
-
+                if(err.name === "ValidationError"){
+                    return res.json(err.errors.name.properties.message);
+                }
                 return res.json("ERROR: UNABLE TO CREATE YOUR INGREDIENTS");
             });
     },

+ 1 - 1
controllers/transactionData.js

@@ -204,7 +204,7 @@ module.exports = {
                     return res.json(err);
                 }
                 if(err.name === "ValidationError"){
-                    return res.json(err.errors.name.properties.message);
+                    return res.json(err.errors[Object.keys(err.errors)[0]].properties.message);
                 }
                 return res.json("ERROR: UNABLE TO CREATE YOUR TRANSACTION");
             });

+ 3 - 3
models/transaction.js

@@ -4,11 +4,11 @@ const TransactionSchema = new mongoose.Schema({
     merchant: {
         type: mongoose.Schema.Types.ObjectId,
         ref: "Merchant",
-        required: [true, "Transaction must contain a reference to a merchant"]
+        required: [true, "MERCHANT IS REQUIRED FOR A TRANSACTION"]
     },
     date: {
         type: Date,
-        required: [true, "Must provide date and time transacted"]
+        required: [true, "DATE MUST BE PROVIDED FOR A TRANSACTION"]
     },
     device: String,
     recipes: [{
@@ -18,7 +18,7 @@ const TransactionSchema = new mongoose.Schema({
         },
         quantity: {
             type: Number,
-            min: [0, "Must be a positive number"]
+            min: [0, "RECIPE QUANTITIES MUST BE A POSITIVE NUMBER"]
         }
     }],
     posId: String

BIN=BIN
uploads/2867256f9a17d8d5fadd7c9379023f16


BIN=BIN
uploads/42f87598ebd0e7b69baa03d99bd3df62


BIN=BIN
uploads/8762434039729c0cea3437495a2b1499


BIN=BIN
uploads/8e38d6391f3c22b3c997daafb1c54dd1


BIN=BIN
uploads/deeea45a4e3cd3babe66f056581f25c5


BIN=BIN
uploads/e2688a022a1fea395d0811c6a701eaf7


BIN=BIN
uploads/f45181433b600ed317201c260383973b