✨ Add user register mutation
🔥 Remove a bunch of legacy code
This commit is contained in:
1 parent
a47de48243
commit
b5c9094b64
34 files changed
+46
-7544
No files matched your search
@@ -0,0 +1,32 @@
|
||||
import strawberry
|
||||
import strawberry_django
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.db import transaction
|
||||
from strawberry_django import auto
|
||||
|
||||
from main import models
|
||||
from main.api.types.users import User
|
||||
|
||||
DjangoUser = get_user_model()
|
||||
|
||||
|
||||
@strawberry_django.input(DjangoUser)
|
||||
class UserInput:
|
||||
email: auto
|
||||
first_name: auto
|
||||
last_name: auto
|
||||
|
||||
|
||||
@strawberry.mutation
|
||||
@transaction.atomic
|
||||
def register_mutation(input: UserInput) -> User:
|
||||
user = DjangoUser.objects.create_user(
|
||||
first_name=input.first_name, last_name=input.last_name, email=input.email, username=input.email
|
||||
)
|
||||
models.UserProfile.objects.create(user=user)
|
||||
return user
|
||||
|
||||
|
||||
@strawberry.type
|
||||
class UsersMutations:
|
||||
register = register_mutation
|
||||
+2
-1
@@ -1,6 +1,7 @@
|
||||
import strawberry
|
||||
|
||||
from main.api.mutations.shop import ShopMutations
|
||||
from main.api.mutations.users import UsersMutations
|
||||
from main.api.queries.inventory import InventoryQueries
|
||||
from main.api.queries.shop import ShopQueries
|
||||
from main.api.queries.users import UsersQueries
|
||||
@@ -12,7 +13,7 @@ class Query(InventoryQueries, ShopQueries, UsersQueries):
|
||||
|
||||
|
||||
@strawberry.type
|
||||
class Mutation(ShopMutations):
|
||||
class Mutation(ShopMutations, UsersMutations):
|
||||
pass
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user