from ariadne import MutationType
from ariadne_jwt.decorators import login_required

from apps.products.models import Product

mutation = MutationType()

@mutation.field('createProduct')
@login_required
def resolve_create_product(self, info, input={}, **kwargs):

    has_product = Product.objects.filter(name=input['name']).first()
    
    if not has_product:

        product = Product(
            name=input['name'],
            price=input['price'],
            quantity=input['quantity']
        )

        if "description" in input.keys():
            product.description = input['description']

        product.save()

        return {
            "ok": True, 
            "product": product
        }

    return {
        "ok": False, 
        "err": "Product with name {} already register".format(has_product.name)
    }

058c30ba75ab89824155c8e4c58e8c79ace00307
<mask token>

<mask token>


@mutation.field('createProduct')
@login_required
def resolve_create_product(self, info, input={}, **kwargs):
    has_product = Product.objects.filter(name=input['name']).first()
    if not has_product:
        product = Product(name=input['name'], price=input['price'],
            quantity=input['quantity'])
        if 'description' in input.keys():
            product.description = input['description']
        product.save()
        return {'ok': True, 'product': product}
    return {'ok': False, 'err': 'Product with name {} already register'.
        format(has_product.name)}

<mask token>
mutation = MutationType()


@mutation.field('createProduct')
@login_required
def resolve_create_product(self, info, input={}, **kwargs):
    has_product = Product.objects.filter(name=input['name']).first()
    if not has_product:
        product = Product(name=input['name'], price=input['price'],
            quantity=input['quantity'])
        if 'description' in input.keys():
            product.description = input['description']
        product.save()
        return {'ok': True, 'product': product}
    return {'ok': False, 'err': 'Product with name {} already register'.
        format(has_product.name)}

from ariadne import MutationType
from ariadne_jwt.decorators import login_required
from apps.products.models import Product
mutation = MutationType()


@mutation.field('createProduct')
@login_required
def resolve_create_product(self, info, input={}, **kwargs):
    has_product = Product.objects.filter(name=input['name']).first()
    if not has_product:
        product = Product(name=input['name'], price=input['price'],
            quantity=input['quantity'])
        if 'description' in input.keys():
            product.description = input['description']
        product.save()
        return {'ok': True, 'product': product}
    return {'ok': False, 'err': 'Product with name {} already register'.
        format(has_product.name)}

from ariadne import MutationType
from ariadne_jwt.decorators import login_required

from apps.products.models import Product

mutation = MutationType()

@mutation.field('createProduct')
@login_required
def resolve_create_product(self, info, input={}, **kwargs):

    has_product = Product.objects.filter(name=input['name']).first()
    
    if not has_product:

        product = Product(
            name=input['name'],
            price=input['price'],
            quantity=input['quantity']
        )

        if "description" in input.keys():
            product.description = input['description']

        product.save()

        return {
            "ok": True, 
            "product": product
        }

    return {
        "ok": False, 
        "err": "Product with name {} already register".format(has_product.name)
    }
