From 2d6fb559ed47e9dae60bb4204aca25d2f3fa4e39 Mon Sep 17 00:00:00 2001 From: Taylor Pubins Date: Fri, 9 Feb 2024 18:18:19 -0700 Subject: [PATCH] Fixed mutiations to match Postman E2E contracts --- src/components/AddExpense/AddExpense.js | 2 +- src/components/AddIncome/AddIncome.js | 2 +- src/components/App/App.js | 1 + src/components/apollo-client/apollo-client.js | 3 +- .../apollo-client/mutations/createExpense.js | 31 ++++++++++--------- .../apollo-client/mutations/createIncome.js | 24 +++++++------- 6 files changed, 35 insertions(+), 28 deletions(-) diff --git a/src/components/AddExpense/AddExpense.js b/src/components/AddExpense/AddExpense.js index f37f01fc..a820167d 100644 --- a/src/components/AddExpense/AddExpense.js +++ b/src/components/AddExpense/AddExpense.js @@ -42,7 +42,7 @@ const AddExpense = ({ totalExpenses, setTotalExpenses, setTransactions }) => { variables: { userId, vendor, - category, + cat: category, amount: amountCents, date, }, diff --git a/src/components/AddIncome/AddIncome.js b/src/components/AddIncome/AddIncome.js index 3ada3d7a..6cf0de7f 100644 --- a/src/components/AddIncome/AddIncome.js +++ b/src/components/AddIncome/AddIncome.js @@ -40,7 +40,7 @@ const AddIncome = ({ totalIncome, setTotalIncome, setTransactions }) => { try { const { data } = await createIncome({ variables: { - userId, + userId, source, amount: amountCents, date, diff --git a/src/components/App/App.js b/src/components/App/App.js index 489537f0..0829db07 100644 --- a/src/components/App/App.js +++ b/src/components/App/App.js @@ -21,6 +21,7 @@ const App = () => { // Hardcoded user, will pull from getUser endpoint soon const userName = "Powdered Toast Man"; const email = "moneybaggins@bigbanktakelilbank.doge" + localStorage.setItem('email', 'user@example.com'); const { totalIncomeData } = useGetIncomes(email); const { totalExpensesData } = useGetExpenses(email); diff --git a/src/components/apollo-client/apollo-client.js b/src/components/apollo-client/apollo-client.js index 4742cd45..84c2d712 100644 --- a/src/components/apollo-client/apollo-client.js +++ b/src/components/apollo-client/apollo-client.js @@ -2,7 +2,8 @@ import { ApolloClient, InMemoryCache, createHttpLink } from "@apollo/client"; import { setContext } from "@apollo/client/link/context"; const httpLink = createHttpLink({ - uri: "https://doughfin-be.onrender.com/graphql", + // uri: "https://doughfin-be.onrender.com/graphql", + uri: "http://localhost:3000/graphql" }); const customHeaders = setContext((_, { headers }) => { diff --git a/src/components/apollo-client/mutations/createExpense.js b/src/components/apollo-client/mutations/createExpense.js index ae5f31c6..b8875da0 100644 --- a/src/components/apollo-client/mutations/createExpense.js +++ b/src/components/apollo-client/mutations/createExpense.js @@ -1,20 +1,23 @@ import { gql, useMutation } from "@apollo/client"; export const CREATE_EXPENSE = gql` -mutation CreateExpense($userId: ID!, $vendor: String!, $category: String!, $amount: Float!, $date: String!) { - createExpense(input: { - userId: $userId, - vendor: $vendor, - category: $category, - amount: $amount, - date: $date - }) { - userId - vendor - category - amount - date - } +mutation CreateExpense($userId: ID!, $vendor: String!, $cat: String!, $amount: Float!, $date: String!) { + createExpense(input: { + userId: $userId, + vendor: $vendor, + category: $cat, + amount: $amount, + date: $date + }) { + userId + expense { + id + vendor + category + amount + date + } + } }` export const useCreateExpense = () => { diff --git a/src/components/apollo-client/mutations/createIncome.js b/src/components/apollo-client/mutations/createIncome.js index 0ed44907..e818570f 100644 --- a/src/components/apollo-client/mutations/createIncome.js +++ b/src/components/apollo-client/mutations/createIncome.js @@ -2,17 +2,19 @@ import { gql, useMutation } from "@apollo/client"; export const CREATE_INCOME = gql` mutation CreateIncome($userId: ID!, $source: String!, $amount: Float!, $date: String!) { - createIncome(input: { - userId: $userId, - source: $source, - amount: $amount, - date: $date - }) { - userId - source - amount - date - } + createIncome(input: { + userId: $userId, + source: $source, + amount: $amount, + date: $date + }) { + userId + income { + source + amount + date + } + } }`; export const useCreateIncome = () => {