All files / src/contexts/userContext queries.tsx

100% Statements 14/14
100% Branches 0/0
100% Functions 0/0
100% Lines 14/14

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197    5x                                                     5x                     5x                 5x                       5x                                   5x               5x                   5x                                                     5x                                                         5x               5x               5x           5x                       5x                  
import { gql } from '@apollo/client';
 
const customerData = gql`
  fragment CustomerData on Customer {
    firstname
    lastname
    suffix
    email
    addresses {
      id
      firstname
      lastname
      company
      street
      city
      region {
        region
        region_id
        region_code
      }
      postcode
      country_code
      telephone
      default_billing
      default_shipping
    }
  }
`;
 
export const CREATE_TOKEN = gql`
  mutation createToken($email: String!, $password: String!) {
    generateCustomerToken(
      email: $email
      password: $password
    ) {
      token
    }
  }
`
 
export const GET_USER = gql`
  query GetUser {
    customer {
      ...CustomerData
    }
  }
  ${customerData}
`
 
export const CHANGE_PASSWORD = gql`
  mutation changePassword($password: String!, $newPassword: String!) {
    changeCustomerPassword(
      currentPassword: $password
      newPassword: $newPassword
    ) {
      id
      email
    }
  }
`
 
export const CREATE_USER = gql`
  mutation CreateUser($firstname: String!, $lastname: String!, $email: String!, $password: String!) {
    createCustomerV2(
      input: {
        firstname: $firstname
        lastname: $lastname
        email: $email
        password: $password
      }
    ) {
      customer {
        ...CustomerData
      }
    }
  }
  ${customerData}
`
 
export const REQUEST_RESET_PASSWORD = gql`
  mutation RequestResetPassword($email: String!) {
    requestPasswordResetEmail(
      email: $email
    )
  }
`
 
export const RESET_PASSWORD = gql`
  mutation changePassword($email: String!, $resetPasswordToken: String!, $newPassword: String!) {
    resetPassword(
      email: $email
      resetPasswordToken: $resetPasswordToken
      newPassword: $newPassword
    )
  }
`
 
export const GET_USER_ORDERS = gql`
  query GetUserOrders($currentPage: Int!, $pageSize: Int!) {
    customer {
      email
      orders(currentPage: $currentPage, pageSize: $pageSize) {
        total_count
        items {
          id
          number
          order_date
          total {
            grand_total {
              value
            }
          }
          status
        }
        page_info {
          current_page
          page_size
          total_pages
        }
      }
    }
  }
`
 
export const GET_USER_ORDER = gql`
  query GetUserOrder($orderNumber: String!) {
    customer {
      email
      orders(filter: {number: {eq: $orderNumber}}) {
        total_count
        items {
          id
          number
          order_date
          total {
            grand_total {
              value
            }
          }
          status
          items {
            product_sku
            product_sale_price {
              value
            }
            quantity_ordered
          }
        }
      }
    }
  }
`
 
export const CREATE_ADDRESS = gql`
  mutation CreateAddress($address: CustomerAddressInput!) {
    createCustomerAddress(input: $address) {
      id
    }
  }
`
 
export const UPDATE_ADDRESS = gql`
  mutation UpdateAddress($addressId: Int!, $address: CustomerAddressInput!) {
    updateCustomerAddress(id: $addressId, input: $address) {
      id
    }
  }
`
 
export const DELETE_ADDRESS = gql`
  mutation DeleteAddress($addressId: Int!) {
    deleteCustomerAddress(id: $addressId)
  }
`
 
export const UPDATE_USER_DATA = gql`
  mutation UpdateUserData($userData: CustomerUpdateInput!) {
    updateCustomerV2(input: $userData) {
      customer {
        email 
        firstname
        lastname
      }
    }
  }
`
 
export const UPDATE_USER_EMAIL = gql`
  mutation UpdateUserEmail($email: String!, $password: String!) {
    updateCustomerEmail(email: $email, password: $password) {
      customer {
        email
      }
    }
  }
`