Browse Source

Feature: Mobile - Implement ticket create mutation.

Florian Liebe 2 years ago
parent
commit
18a98c40db

+ 10 - 2
.graphql_code_generator.yml

@@ -7,8 +7,16 @@ documents:
   ['app/frontend/shared/**/*.graphql', 'app/frontend/apps/**/*.graphql']
 generates:
   ./app/frontend/shared/graphql/types.ts:
-    - typescript
-    - typescript-operations
+    config:
+      scalars:
+        BinaryString: string
+        NonEmptyString: string
+        FormId: string
+        ISO8601Date: string
+        ISO8601DateTime: string
+    plugins:
+      - typescript
+      - typescript-operations
   ./app/frontend/:
     preset: near-operation-file
     presetConfig:

+ 3 - 3
app/frontend/apps/mobile/pages/ticket/__tests__/mocks/detail-view.ts

@@ -102,7 +102,7 @@ export const defaultArticles = (): TicketArticlesQuery =>
             internal: false,
             body: '<p>Body <b>of a test ticket</b></p>',
             sender: {
-              __typename: 'TicketArticleType',
+              __typename: 'TicketArticleSender',
               name: 'Customer',
             },
             type: {
@@ -153,7 +153,7 @@ export const defaultArticles = (): TicketArticlesQuery =>
             internal: false,
             body: '<p>energy equals power times time</p>',
             sender: {
-              __typename: 'TicketArticleType',
+              __typename: 'TicketArticleSender',
               name: 'Agent',
             },
             type: {
@@ -187,7 +187,7 @@ export const defaultArticles = (): TicketArticlesQuery =>
             internal: true,
             body: '<p>only agents can see this haha</p>',
             sender: {
-              __typename: 'TicketArticleType',
+              __typename: 'TicketArticleSender',
               name: 'Agent',
             },
             type: {

+ 26 - 0
app/frontend/apps/mobile/pages/ticket/graphql/mutations/create.api.ts

@@ -0,0 +1,26 @@
+import * as Types from '../../../../../../shared/graphql/types';
+
+import gql from 'graphql-tag';
+import { TicketAttributesFragmentDoc } from '../fragments/ticketAttributes.api';
+import { ErrorsFragmentDoc } from '../../../../../../shared/graphql/fragments/errors.api';
+import * as VueApolloComposable from '@vue/apollo-composable';
+import * as VueCompositionApi from 'vue';
+export type ReactiveFunction<TParam> = () => TParam;
+
+export const TicketCreateDocument = gql`
+    mutation ticketCreate($input: TicketCreateInput!) {
+  ticketCreate(input: $input) {
+    ticket {
+      ...ticketAttributes
+    }
+    errors {
+      ...errors
+    }
+  }
+}
+    ${TicketAttributesFragmentDoc}
+${ErrorsFragmentDoc}`;
+export function useTicketCreateMutation(options: VueApolloComposable.UseMutationOptions<Types.TicketCreateMutation, Types.TicketCreateMutationVariables> | ReactiveFunction<VueApolloComposable.UseMutationOptions<Types.TicketCreateMutation, Types.TicketCreateMutationVariables>>) {
+  return VueApolloComposable.useMutation<Types.TicketCreateMutation, Types.TicketCreateMutationVariables>(TicketCreateDocument, options);
+}
+export type TicketCreateMutationCompositionFunctionResult = VueApolloComposable.UseMutationReturn<Types.TicketCreateMutation, Types.TicketCreateMutationVariables>;

+ 10 - 0
app/frontend/apps/mobile/pages/ticket/graphql/mutations/create.graphql

@@ -0,0 +1,10 @@
+mutation ticketCreate($input: TicketCreateInput!) {
+  ticketCreate(input: $input) {
+    ticket {
+      ...ticketAttributes
+    }
+    errors {
+      ...errors
+    }
+  }
+}

File diff suppressed because it is too large
+ 118 - 14
app/frontend/shared/graphql/types.ts


+ 1 - 1
app/frontend/shared/types/form.ts

@@ -42,7 +42,7 @@ export enum FormSchemaExtendType {
 }
 
 export interface FormDefaultProps {
-  formId?: string
+  formId: string
   link?: RouteLocationRaw
   labelPlaceholder?: string[]
   internal?: boolean

+ 0 - 4
app/graphql/gql/mutations/organization/update.rb

@@ -9,10 +9,6 @@ module Gql::Mutations
 
     field :organization, Gql::Types::OrganizationType, description: 'The updated organization.'
 
-    def load_id(id:)
-      Gql::ZammadSchema.verified_object_from_id(id, type: ::Organization)
-    end
-
     # TODO/FIXME: Remove this again when we have a proper solution to deal with Pundit stuff in GraphQL mutations.
     def self.authorize(_obj, ctx)
       ctx[:current_user].permissions?(['admin.organization', 'ticket.agent'])

+ 19 - 0
app/graphql/gql/mutations/ticket/create.rb

@@ -0,0 +1,19 @@
+# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
+
+module Gql::Mutations
+  class Ticket::Create < BaseMutation
+    description 'Create a new ticket.'
+
+    argument :input, Gql::Types::Input::Ticket::CreateInputType, description: 'The ticket data'
+
+    field :ticket, Gql::Types::TicketType, description: 'The created user.'
+
+    def self.authorize(_obj, ctx)
+      ctx[:current_user].permissions?(['ticket.agent', 'ticket.customer'])
+    end
+
+    def resolve(input:)
+      { ticket: Service::Ticket::Create.new(current_user: context.current_user).execute(ticket_data: input.to_h) }
+    end
+  end
+end

+ 0 - 4
app/graphql/gql/mutations/user/update.rb

@@ -9,10 +9,6 @@ module Gql::Mutations
 
     field :user, Gql::Types::UserType, description: 'The created user.'
 
-    def load_id(id:)
-      Gql::ZammadSchema.verified_object_from_id(id, type: ::User, user: context.current_user)
-    end
-
     def authorized?(current_user:, input:)
       Pundit.authorize(context.current_user, current_user, :update?)
     end

+ 2 - 2
app/graphql/gql/types/base_input_object.rb

@@ -25,8 +25,8 @@ module Gql::Types
     end
 
     def prepare
-      self.class.transformers.reduce(super) do |result, t|
-        send(t, result)
+      self.class.transformers.reduce(super) do |result, transformer|
+        send(transformer, result)
       end
     end
   end

Some files were not shown because too many files changed in this diff