|
1 | 1 | import graphene
|
2 | 2 | from nxtbn.core.admin_permissions import check_user_permissions
|
3 |
| -from nxtbn.product.admin_types import CategoryTranslationType, CollectionTranslationType, ProductTagTranslationType, ProductTranslationType, ProductVariantTranslationType, SupplierTranslationType |
4 |
| -from nxtbn.product.models import CategoryTranslation, CollectionTranslation, ProductTagTranslation, ProductTranslation, ProductVariantTranslation, SupplierTranslation |
| 3 | +from nxtbn.product.admin_types import CategoryTranslationType, CategoryType, CollectionTranslationType, ProductTagTranslationType, ProductTranslationType, ProductVariantTranslationType, SupplierTranslationType |
| 4 | +from nxtbn.product.models import Category, CategoryTranslation, CollectionTranslation, ProductTagTranslation, ProductTranslation, ProductVariantTranslation, SupplierTranslation |
5 | 5 | from nxtbn.users import UserRole
|
6 | 6 |
|
7 | 7 |
|
| 8 | +class NameSecriptionSEOInputType(graphene.InputObjectType): |
| 9 | + name = graphene.String(required=True) |
| 10 | + description = graphene.String(required=True) |
| 11 | + meta_title = graphene.String(required=True) |
| 12 | + meta_description = graphene.String(required=True) |
| 13 | + |
| 14 | + |
| 15 | +class UpdateCategoryMutation(graphene.Mutation): |
| 16 | + class Arguments: |
| 17 | + input = NameSecriptionSEOInputType(required=True) |
| 18 | + id = graphene.Int(required=True) |
| 19 | + |
| 20 | + category = graphene.Field(CategoryType) |
| 21 | + |
| 22 | + def mutate(self, info, id, input): |
| 23 | + check_user_permissions(info, allowed_roles=[UserRole.PRODUCT_MANAGER, UserRole.STORE_MANAGER, UserRole.ADMIN]) |
| 24 | + category = Category.objects.get(id=id) |
| 25 | + category.name = input.name |
| 26 | + category.description = input.description |
| 27 | + category.meta_title = input.meta_title |
| 28 | + category.meta_description = input.meta_description |
| 29 | + category.save() |
| 30 | + |
| 31 | + return UpdateCategoryMutation(category=category) |
| 32 | + |
| 33 | + |
| 34 | +# ================================ |
| 35 | +# All Transaltoin Mutations |
| 36 | +# ================================ |
8 | 37 |
|
9 | 38 | class UpdateProductTranslatoinMutation(graphene.Mutation):
|
10 | 39 | class Arguments:
|
@@ -157,6 +186,9 @@ def mutate(self, info, base_collection_id, lang_code, name, description, meta_ti
|
157 | 186 |
|
158 | 187 |
|
159 | 188 | class ProductMutation(graphene.ObjectType):
|
| 189 | + update_category = UpdateCategoryMutation.Field() |
| 190 | + |
| 191 | + # All Transaltion Mutations |
160 | 192 | update_product_translation = UpdateProductTranslatoinMutation.Field()
|
161 | 193 | update_category_translation = UpdateCategoryTranslationMutation.Field()
|
162 | 194 | update_supplier_translation = UpdateSupplierTranslationMutation.Field()
|
|
0 commit comments