Эх сурвалжийг харах

Add code to backend to add new merchant to owner in case they are trying to add a new merchant to their account.

Lee Morgan 5 жил өмнө
parent
commit
0b15882c26
1 өөрчлөгдсөн 17 нэмэгдсэн , 11 устгасан
  1. 17 11
      controllers/merchantData.js

+ 17 - 11
controllers/merchantData.js

@@ -16,6 +16,7 @@ module.exports = {
         email: registration email,
         password: password,
         confirmPassword: confirmation password
+        owner: String (id of the owner, new owner of undefined)
     }
     Redirects to /dashboard
     */
@@ -43,17 +44,22 @@ module.exports = {
         let expirationDate = new Date();
         expirationDate.setDate(expirationDate.getDate() + 90);
 
-        let owner = new Owner({
-            email: email,
-            password: hash,
-            createdAt: new Date(),
-            status: ["unverified"],
-            session: {
-                sessionId: helper.generateId(25),
-                expiration: expirationDate
-            },
-            merchants: []
-        });
+        let owner = {};
+        if(req.body.owner === undefined){
+            owner = new Owner({
+                email: email,
+                password: hash,
+                createdAt: new Date(),
+                status: ["unverified"],
+                session: {
+                    sessionId: helper.generateId(25),
+                    expiration: expirationDate
+                },
+                merchants: []
+            });
+        }else{
+            owner = await Owner.findOne({_id: req.body.owner})
+        }
 
         let merchant = new Merchant({
             owner: owner._id,