Lee Morgan 5 роки тому
батько
коміт
b275baad3a

+ 5 - 0
app.js

@@ -6,6 +6,7 @@ const https = require("https");
 const fs = require("fs");
 const cssmerger = require("cssmerger");
 const esbuild = require("esbuild");
+const fileUpload = require("express-fileupload");
 
 const app = express();
 
@@ -67,6 +68,10 @@ mongoose.connect(`mongodb://127.0.0.1:27017/inventory-management`, mongooseOptio
 
 app.use(compression());
 app.use(express.urlencoded({extended: true}));
+app.use(fileUpload({
+    limits: {fileSize: 1024 * 1024},
+    useTempFiles: true
+}));
 app.use(express.json());
 app.use(session(sessionOptions));
 require("./routes")(app);

+ 30 - 0
controllers/admin.js

@@ -0,0 +1,30 @@
+const Merchant = require("../models/merchant.js");
+const fs = require("fs");
+
+module.exports = {
+    /*
+    POST: Adding data for admins
+    req.body = {
+        password: String
+        id: String <merchant id>
+    }
+    req.files = {
+        ingredients: txt
+        recipes: txt 
+    }
+    */
+    addData: function(req, res){
+        if(req.body.password !== process.env.ADMIN_PASS) return res.json("bad password");
+
+        Merchant.findOne({_id: req.body.id})
+            .then((merchant)=>{
+                let data = fs.readFileSync(req.files.ingredients.tempFilePath).toString();
+                data = data.split("/n");
+
+                console.log(data);
+            })
+            .catch((err)=>{
+                return res.json("ERROR: A whoopsie has been made");
+            });
+    }
+}

+ 60 - 0
package-lock.json

@@ -17,6 +17,7 @@
         "ejs": "^2.7.4",
         "esbuild": "^0.11.20",
         "express": "^4.17.1",
+        "express-fileupload": "^1.2.1",
         "mongoose": "^5.12.4",
         "multer": "^1.4.2",
         "xlsx": "^0.16.8"
@@ -513,6 +514,39 @@
         "node": ">= 0.10.0"
       }
     },
+    "node_modules/express-fileupload": {
+      "version": "1.2.1",
+      "resolved": "https://registry.npmjs.org/express-fileupload/-/express-fileupload-1.2.1.tgz",
+      "integrity": "sha512-fWPNAkBj+Azt9Itmcz/Reqdg3LeBfaXptDEev2JM8bCC0yDptglCnlizhf0YZauyU5X/g6v7v4Xxqhg8tmEfEA==",
+      "dependencies": {
+        "busboy": "^0.3.1"
+      },
+      "engines": {
+        "node": ">=8.0.0"
+      }
+    },
+    "node_modules/express-fileupload/node_modules/busboy": {
+      "version": "0.3.1",
+      "resolved": "https://registry.npmjs.org/busboy/-/busboy-0.3.1.tgz",
+      "integrity": "sha512-y7tTxhGKXcyBxRKAni+awqx8uqaJKrSFSNFSeRG5CsWNdmy2BIK+6VGWEW7TZnIO/533mtMEA4rOevQV815YJw==",
+      "dependencies": {
+        "dicer": "0.3.0"
+      },
+      "engines": {
+        "node": ">=4.5.0"
+      }
+    },
+    "node_modules/express-fileupload/node_modules/dicer": {
+      "version": "0.3.0",
+      "resolved": "https://registry.npmjs.org/dicer/-/dicer-0.3.0.tgz",
+      "integrity": "sha512-MdceRRWqltEG2dZqO769g27N/3PXfcKl04VhYnBlo2YhH7zPi88VebsjTKclaOyiuMaGU72hTfw3VkUitGcVCA==",
+      "dependencies": {
+        "streamsearch": "0.1.2"
+      },
+      "engines": {
+        "node": ">=4.5.0"
+      }
+    },
     "node_modules/finalhandler": {
       "version": "1.1.2",
       "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.1.2.tgz",
@@ -1584,6 +1618,32 @@
         "vary": "~1.1.2"
       }
     },
+    "express-fileupload": {
+      "version": "1.2.1",
+      "resolved": "https://registry.npmjs.org/express-fileupload/-/express-fileupload-1.2.1.tgz",
+      "integrity": "sha512-fWPNAkBj+Azt9Itmcz/Reqdg3LeBfaXptDEev2JM8bCC0yDptglCnlizhf0YZauyU5X/g6v7v4Xxqhg8tmEfEA==",
+      "requires": {
+        "busboy": "^0.3.1"
+      },
+      "dependencies": {
+        "busboy": {
+          "version": "0.3.1",
+          "resolved": "https://registry.npmjs.org/busboy/-/busboy-0.3.1.tgz",
+          "integrity": "sha512-y7tTxhGKXcyBxRKAni+awqx8uqaJKrSFSNFSeRG5CsWNdmy2BIK+6VGWEW7TZnIO/533mtMEA4rOevQV815YJw==",
+          "requires": {
+            "dicer": "0.3.0"
+          }
+        },
+        "dicer": {
+          "version": "0.3.0",
+          "resolved": "https://registry.npmjs.org/dicer/-/dicer-0.3.0.tgz",
+          "integrity": "sha512-MdceRRWqltEG2dZqO769g27N/3PXfcKl04VhYnBlo2YhH7zPi88VebsjTKclaOyiuMaGU72hTfw3VkUitGcVCA==",
+          "requires": {
+            "streamsearch": "0.1.2"
+          }
+        }
+      }
+    },
     "finalhandler": {
       "version": "1.1.2",
       "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.1.2.tgz",

+ 1 - 0
package.json

@@ -27,6 +27,7 @@
     "ejs": "^2.7.4",
     "esbuild": "^0.11.20",
     "express": "^4.17.1",
+    "express-fileupload": "^1.2.1",
     "mongoose": "^5.12.4",
     "multer": "^1.4.2",
     "xlsx": "^0.16.8"

+ 5 - 0
routes.js

@@ -9,6 +9,7 @@ const informationPages = require("./controllers/informationPages.js");
 const emailVerification = require("./controllers/emailVerification.js");
 const passwordReset = require("./controllers/passwordReset.js");
 const squareData = require("./controllers/squareData.js");
+const admin = require("./controllers/admin.js");
 
 const session = require("./middleware.js").verifySession;
 const banner = require("./middleware.js").formatBanner;
@@ -92,4 +93,8 @@ module.exports = function(app){
     app.get("/recipes/update/square", session, squareData.updateRecipes);
     app.get("/square/locations", session, squareData.getLocations);
     app.get("/square/add/:location", session, squareData.addMerchant);
+
+    //Admin
+    app.get("/admin/create", (req, res)=>{res.sendFile(`${__dirname}/views/newTest.html`)});
+    app.post("/admin/create", admin.addData);
 }

+ 3 - 0
tmp/tmp-1-1626255598484

@@ -0,0 +1,3 @@
+thingon1
+thingtwo
+thing3,dirtybitchtits

+ 3 - 0
tmp/tmp-1-1626255671953

@@ -0,0 +1,3 @@
+thingon1
+thingtwo
+thing3,dirtybitchtits

+ 3 - 1
views/dashboardPage/js/classes/Merchant.js

@@ -77,7 +77,8 @@ class Merchant{
             recipes,
             transactions,
             address,
-            owner
+            owner,
+            id
         ){
         this._name = name;
         this._pos = pos;
@@ -92,6 +93,7 @@ class Merchant{
             merchants: owner.merchants,
             name: owner.name
         };
+        this.id = id;
         
         //populate ingredients
         for(let i = 0; i < ingredients.length; i++){

+ 2 - 1
views/dashboardPage/js/dashboard.js

@@ -30,7 +30,8 @@ window.merchant = new Merchant(
     data.merchant.recipes,
     data.transactions,
     (data.merchant.address === undefined) ? "" : data.merchant.address.full,
-    data.owner
+    data.owner,
+    data.merchant._id
 );
 
 controller = {

+ 38 - 0
views/newTest.html

@@ -0,0 +1,38 @@
+<!DOCTYPE html>
+<html lang="en">
+    <head>
+        <meta charset="utf-8">
+        <title>The Subline</title>
+        <style>
+            form{
+                display:flex;
+                flex-direction: column;
+            }
+
+            form > *{
+                margin: 10px;
+            }
+        </style>
+    </head>
+    <body>
+        <form action="/admin/create" method="post" enctype="multipart/form-data">
+            <label>Password
+                <input name="password" type="password" required>
+            </label>
+
+            <label>Merchant Id
+                <input name="id" type="text" required>
+            </label>
+
+            <label>Ingredients
+                <input name="ingredients" type="file">
+            </label>
+
+            <label>Recipes
+                <input name="recipes" type="file">
+            </label>
+
+            <input type="submit" value="Submit">
+        </form>
+    </body>
+</html>