Refactor User mutation, use inheritance
@@ -4,9 +4,7 @@ from .forms import LoginForm, RegisterForm, UpdateUserForm
from .types import MeUser
-class Login(FormMutation):
- @classmethod
- def transform(cls, result):
+def get_me_user_type(result):
return MeUser(
id=result.id,
email=result.email,
@@ -25,58 +23,31 @@ class Login(FormMutation):
phone_number=result.phone_number,
)
- class Meta:
- form_class = LoginForm
- output_types = (MeUser,)
-
-class Register(FormMutation):
+class BaseUserMutation(FormMutation):
@classmethod
def transform(cls, result):
- return MeUser(
- id=result.id,
- email=result.email,
- first_name=result.first_name,
- last_name=result.last_name,
- gender=result.gender,
- open_to_recruiting=result.open_to_recruiting,
- date_birth=result.date_birth,
- business_name=result.business_name,
- fiscal_code=result.fiscal_code,
- vat_number=result.vat_number,
- recipient_code=result.recipient_code,
- pec_address=result.pec_address,
- address=result.address,
- country=result.country,
- phone_number=result.phone_number,
- )
+ return get_me_user_type(result)
class Meta:
+
form_class = RegisterForm
output_types = (MeUser,)
-class Update(FormMutation):
- @classmethod
- def transform(cls, result):
- return MeUser(
- id=result.id,
- email=result.email,
- first_name=result.first_name,
- last_name=result.last_name,
- gender=result.gender,
- open_to_recruiting=result.open_to_recruiting,
- date_birth=result.date_birth,
- business_name=result.business_name,
- fiscal_code=result.fiscal_code,
- vat_number=result.vat_number,
- recipient_code=result.recipient_code,
- pec_address=result.pec_address,
- address=result.address,
- country=result.country,
- phone_number=result.phone_number,
- )
+class Login(BaseUserMutation):
+ class Meta:
+ form_class = LoginForm
+ output_types = (MeUser,)
+
+
+class Register(BaseUserMutation):
+ class Meta:
+ form_class = RegisterForm
+ output_types = (MeUser,)
+
+class Update(BaseUserMutation):
class Meta:
form_class = UpdateUserForm
output_types = (MeUser,)
