Exemplo n.º 1
0
 def perform_mutation(self, info, input):
     user_exists = User.objects.filter(email=input['email']).exists()
     if not user_exists:
         if len(input['password']) >= 8:
             user = User.objects.create_user(input['email'], input['password'])
             token = get_token(user)
             update_last_login(None, user)
             return RegisterUser(token=token, user=user)
         else:
             raise ValidationError(form_errors={'password': '******'})
     else:
         raise ValidationError(form_errors={'email': 'This email is already taken.'})
Exemplo n.º 2
0
def get_country(country_id, field_name='country'):
    country = None
    try:
        country = Country.objects.get(id=country_id)
        return country
    except ObjectDoesNotExist:
        raise ValidationError(form_errors={field_name: 'Country not found'})
Exemplo n.º 3
0
def get_trip(trip_id, field_name='trip'):
    try:
        return Trip.objects.get(id=trip_id)
    except ObjectDoesNotExist:
        raise ValidationError(form_errors={field_name: 'Trip not found'})
Exemplo n.º 4
0
def get_category_in_trip(category_id, trip_id, field_name='category'):
    try:
        return TripCategory.objects.get(id=category_id, trip_id=trip_id)
    except ObjectDoesNotExist:
        raise ValidationError(form_errors={field_name: 'Category not found'})
Exemplo n.º 5
0
def get_expense_in_trip(expense_id, trip_id, field_name='expense'):
    try:
        return Expense.objects.get(id=expense_id, trip_id=trip_id)
    except ObjectDoesNotExist:
        raise ValidationError(form_errors={field_name: 'Expense not found'})
Exemplo n.º 6
0
def get_currency(currency_id, field_name='currency'):
    try:
        currency = Currency.objects.get(id=currency_id)
        return currency
    except ObjectDoesNotExist:
        raise ValidationError(form_errors={field_name: 'Currency not found'})
Exemplo n.º 7
0
 def mutate(cls, root, info, **data):
     try:
         return cls.perform_mutation(root, info, **data)
     except DjangoValidationError as django_validation_error:
         raise ValidationError(
             form_errors=django_validation_error.message_dict)