import gql from 'graphql-tag' ; import { IForm , Action } from '@client/forms' ; import { IApplication } from '@client/applications' ; import { draftToGqlTransformer , appendGqlMetadataFromDraft } from '@client/transformer' ; const SUBMIT_DEATH_APPLICATION = gql `
  mutation submitMutation($details: DeathRegistrationInput!) {
    createDeathRegistration(details: $details) {
      trackingId
      compositionId
    }
  }
` ; const APPROVE_DEATH_APPLICATION = gql `
  mutation submitMutation($id: ID!, $details: DeathRegistrationInput) {
    markDeathAsValidated(id: $id, details: $details)
  }
` ; const REGISTER_DEATH_APPLICATION = gql `
  mutation submitMutation($id: ID!, $details: DeathRegistrationInput) {
    markDeathAsRegistered(id: $id, details: $details) {
      id
      registration {
        id
        status {
          id
          user {
            id
            name {
              use
              firstNames
              familyName
            }
            role
          }
          location {
            id
            name
            alias
          }
          office {
            name
            alias
            address {
              district
              state
            }
          }
          type
          timestamp
          comments {
            comment
          }
        }
      }
    }
  }
` ; const REJECT_DEATH_APPLICATION = gql `
  mutation submitMutation($id: String!, $reason: String!, $comment: String!) {
    markEventAsVoided(id: $id, reason: $reason, comment: $comment)
  }
` ; const COLLECT_DEATH_CERTIFICATE = gql `
  mutation submitMutation($id: ID!, $details: DeathRegistrationInput!) {
    markDeathAsCertified(id: $id, details: $details)
  }
` ; export function getDeathMutationMappings ( action , payload ? , form ? , draft ? ) { let gqlDetails = { } ; if ( form && draft ) { gqlDetails = draftToGqlTransformer ( form , draft . data , draft . id ) ; appendGqlMetadataFromDraft ( draft , gqlDetails ) ; } switch ( action ) { case Action . SUBMIT_FOR_REVIEW : return { mutation : SUBMIT_DEATH_APPLICATION , variables : { details : gqlDetails } , dataKey : 'createDeathRegistration' } ; case Action . APPROVE_APPLICATION : return { mutation : APPROVE_DEATH_APPLICATION , variables : { id : draft && draft . id , details : gqlDetails } , dataKey : 'markDeathAsValidated' } ; case Action . REGISTER_APPLICATION : return { mutation : REGISTER_DEATH_APPLICATION , variables : { id : draft && draft . id , details : gqlDetails } , dataKey : 'markDeathAsRegistered' } ; case Action . REJECT_APPLICATION : return { mutation : REJECT_DEATH_APPLICATION , variables : { ... payload } , dataKey : 'markEventAsVoided' } ; case Action . COLLECT_CERTIFICATE : return { mutation : COLLECT_DEATH_CERTIFICATE , variables : { id : draft && draft . id , details : gqlDetails } , dataKey : 'markDeathAsCertified' } ; default : return null ; } }