Преглед изворни кода

Create owner model.
Remove some fields from Merchant model to put in the Owner model.

Lee Morgan пре 5 година
родитељ
комит
bad7d22241
2 измењених фајлова са 47 додато и 33 уклоњено
  1. 1 33
      models/merchant.js
  2. 46 0
      models/owner.js

+ 1 - 33
models/merchant.js

@@ -2,10 +2,6 @@ const isSanitary = require("../controllers/helper.js").isSanitary;
 
 const mongoose = require("mongoose");
 
-let emailValid = (value)=>{
-    return /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(value);
-}
-
 const MerchantSchema = new mongoose.Schema({
     name: {
         type: String,
@@ -15,32 +11,10 @@ const MerchantSchema = new mongoose.Schema({
             message: "NAME CONTAINS ILLEGAL CHARACTERS"
         }
     },
-    email: {
-        type: String,
-        required: [true, "EMAIL IS REQUIRED"],
-        validate: {
-            validator: emailValid,
-            message: "INVALID EMAIL ADDRESS"
-        },
-        index: true
-    },
-    password: String,
-    pos: {
-        type: String,
-        required: true
-    },
-    square: {
-        id: String,
-        accessToken: String,
-        expires: Date,
-        refreshToken: String,
-        location: String
-    },
     createdAt: {
         type: Date,
         default: new Date()
     },
-    status: [],
     inventory: [{
         ingredient: {
             type: mongoose.Schema.Types.ObjectId,
@@ -60,13 +34,7 @@ const MerchantSchema = new mongoose.Schema({
         type: mongoose.Schema.Types.ObjectId,
         ref: "Recipe"
     }],
-    session: {
-        sessionId: {
-            type: String,
-            index: true
-        },
-        expiration: Date
-    }
+    
 });
 
 module.exports = mongoose.model("Merchant", MerchantSchema);

+ 46 - 0
models/owner.js

@@ -0,0 +1,46 @@
+const mongoose = require("mongoose");
+
+let emailValid = (value)=>{
+    return /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(value);
+}
+
+const OwnerSchema = new mongoose.Schema({
+    email: {
+        type: String,
+        required: [true, "EMAIL IS REQUIRED"],
+        validate: {
+            validator: emailValid,
+            message: "INVALID EMAIL ADDRESS"
+        },
+        index: true
+    },
+    password: {
+        type: String,
+        required: true
+    },
+    pos: {
+        type: String,
+        required: true
+    },
+    square: {
+        id: String,
+        accessToken: String,
+        expires: Date,
+        refreshToken: String,
+        location: String
+    },
+    createdAt: {
+        type: Date,
+        default: new Date()
+    },
+    status: [],
+    session: {
+        sessionId: {
+            type: String,
+            index: true
+        },
+        expiration: Date
+    }
+});
+
+module.exports = mongoose.model("Owner", OwnerSchema);