Browse Source

fix userUpsertError

ilya_shyian 2 years ago
parent
commit
8bd039842f
2 changed files with 26 additions and 26 deletions
  1. 23 26
      store_back/apps/authAPI/schema.py
  2. 3 0
      store_back/apps/orders/schema.py

+ 23 - 26
store_back/apps/authAPI/schema.py

@@ -167,37 +167,34 @@ class UserUpsert(graphene.Mutation):
                 except:
                     raise Exception("Не вірні дані (аватар)")
 
-        try:
-            _id = user._id
-            new_user = User.objects.get(_id = _id)
-            if not info.context.user.is_superuser:
+        if "_id" in user:
+            if not info.context.user.is_authenticated:
                 raise Exception("Authentication credentials were not provided")
 
-            user.pop("_id",None)
-            new_user.__dict__.update(**user)
-
-            if password:
-                new_user.set_password(password)
-    
-
-        except Exception as e:
 
-            if info.context.user.is_authenticated:
-                try:
-                    new_user = User.objects.get(username = info.context.user.username)
-                    new_user.__dict__.update(**user)
-                    if password:
-                        new_user.set_password(password)
-                except:
-                    raise Exception("Не вірні дані")
-            else:
-                try:
-                    User.objects.get(username = user.username)
-                    raise Exception("Username вже зайнятий")
-                except:
-                    pass
+            if str(info.context.user._id) != user._id and not info.context.user.is_superuser:
+                raise Exception("Authentication credentials were not provided")
 
+            
+            try:
+                _id = user._id
+                new_user = User.objects.get(_id = _id)
+                user.pop("_id",None)
+
+                new_user.__dict__.update(**user)
+
+                if password:
+                    new_user.set_password(password)
+            except:
+                raise Exception("Не вірні дані")
+                
+    
+        else:
+            if info.context.user.is_authenticated and not info.context.user.is_superuser:
+                new_user = User.objects.get(username = info.context.user.username )
+            else:                      
                 new_user = User.objects.create_user(username = user.username,password=user.password)
+            
 
         if ava:
             if ava == "null":

+ 3 - 0
store_back/apps/orders/schema.py

@@ -209,6 +209,9 @@ class Query(graphene.ObjectType):
 
 
 
+
+
+
 class OrderUpsert(graphene.Mutation):
 
     class Arguments: