Fakultas Ilmu Komputer UI

Commit a61b02a7 authored by addffa's avatar addffa
Browse files

[GREEN] implementasi mutation pada transaction

parent 6174ef9e
Pipeline #51296 passed with stage
in 9 minutes and 25 seconds
......@@ -9,6 +9,9 @@ from .mustahik.mutations import (
)
from .mustahik.query import MustahikQuery
from .transaction.query import TransactionQuery
from .transaction.mutations import (
MuzakkiMutation, TransactionMutation, ZakatTransactionMutation
)
ABOUT = ('Si Zakat merupakan sistem informasi untuk membantu masjid dalam '
'mengelola transaksi zakat. Sistem ini dibuat oleh tim lab 1231, '
......@@ -31,5 +34,9 @@ class Mutation(graphene.ObjectType):
data_source_pekerja_mutation = DataSourcePekerjaMutation.Field()
delete_data_source = DeleteDataSource.Field()
muzakki_mutation = MuzakkiMutation.Field()
transaction_mutation = TransactionMutation.Field()
zakat_transaction_mutation = ZakatTransactionMutation.Field()
schema = graphene.Schema(query=Query, mutation=Mutation)
from django import forms
from .models import Muzakki, Transaction, ZakatTransaction
class MuzakkiForm(forms.ModelForm):
class Meta:
model = Muzakki
fields = [
'no_ktp',
'name',
'phone',
]
class TransactionForm(forms.ModelForm):
class Meta:
model = Transaction
fields = [
'payment_type',
'goods_delivery_type',
'pick_up_address',
'transfer_receipt',
'payment_confirmation',
'goods_confirmation',
]
class ZakatTransactionForm(forms.ModelForm):
class Meta:
model = ZakatTransaction
fields = [
'value',
'zakat_type',
'muzakki',
'transaction',
]
import graphene
from graphene_django.forms.mutation import DjangoModelFormMutation
from graphene_django.types import ErrorType
from sizakat.validators import validate_photo
from .forms import MuzakkiForm, TransactionForm, ZakatTransactionForm
from .types import MuzakkiType, TransactionType, ZakatTransactionType
class MuzakkiMutation(DjangoModelFormMutation):
muzakki = graphene.Field(MuzakkiType)
class Meta:
form_class = MuzakkiForm
class TransactionMutation(DjangoModelFormMutation):
transaction = graphene.Field(TransactionType)
class Meta:
form_class = TransactionForm
@classmethod
def mutate_and_get_payload(cls, root, info, **input):
form = cls.get_form(root, info, **input)
transfer_receipt = info.context.FILES.get('transfer_receipt', None)
if transfer_receipt and not validate_photo(transfer_receipt):
form.add_error('transfer_receipt', 'invalid format')
if form.is_valid():
transaction = form.save(commit=False)
if transfer_receipt:
transaction.transfer_receipt = transfer_receipt
transaction.save()
kwargs = {cls._meta.return_field_name: transaction}
return cls(errors=[], **kwargs)
else:
errors = ErrorType.from_errors(form.errors)
return cls(errors=errors)
class ZakatTransactionMutation(DjangoModelFormMutation):
zakat_trasaction = graphene.Field(ZakatTransactionType)
class Meta:
form_class = ZakatTransactionForm
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