Fakultas Ilmu Komputer UI

Commit 92fe44ba authored by addffa's avatar addffa
Browse files

[REFACTOR] mengubah mutasi upload photo

parent 6123747a
......@@ -24,13 +24,14 @@ class MustahikMutation(DjangoModelFormMutation):
@classmethod
def mutate_and_get_payload(cls, root, info, **input):
form = cls.get_form(root, info, **input)
photo = info.context.FILES['photo']
if not validate_photo(photo):
photo = info.context.FILES.get('photo', None)
if photo and not validate_photo(photo):
form.add_error('photo', 'invalid photo format')
if form.is_valid():
mustahik = form.save(commit=False)
mustahik.photo = photo
if photo:
mustahik.photo = photo
mustahik.save()
kwargs = {cls._meta.return_field_name: mustahik}
return cls(errors=[], **kwargs)
......
......@@ -157,6 +157,7 @@ class MustahikGraphQLTestCase(GraphQLTestCase):
"birthdate": "1998-03-12",
"status": "MISKIN",
"gender": "L",
"photo": "",
"dataSource": data_source.pk
}
)
......@@ -205,6 +206,7 @@ class MustahikGraphQLTestCase(GraphQLTestCase):
"birthdate": "1987-06-05",
"status": "MUSAFIR",
"gender": "L",
"photo": "",
"id": mustahik.pk,
"dataSource": data_source.pk
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment