From afb443ac0df3ccd2b037e2a98f2e282cd1138384 Mon Sep 17 00:00:00 2001 From: mattwr18 Date: Mon, 11 Nov 2019 19:14:06 +0100 Subject: [PATCH] Update resolver to match one Donations node - there should only ever be one Donations node to start off with, if that changes in the future for some reason, then we'd need to look into changing the match to something that makes more sense. --- backend/src/schema/resolvers/donations.js | 7 ++++++- backend/src/schema/resolvers/donations.spec.js | 8 ++++---- backend/src/schema/types/type/Donations.gql | 3 ++- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/backend/src/schema/resolvers/donations.js b/backend/src/schema/resolvers/donations.js index 1c7aee8d4..4057748e0 100644 --- a/backend/src/schema/resolvers/donations.js +++ b/backend/src/schema/resolvers/donations.js @@ -1,13 +1,18 @@ +import uuid from 'uuid/v4' + export default { Mutation: { UpdateDonations: async (_parent, params, context, _resolveInfo) => { const { driver } = context const session = driver.session() let donations + params.id = params.id || uuid() + const writeTxResultPromise = session.writeTransaction(async txc => { const updateDonationsTransactionResponse = await txc.run( ` - MATCH (donations:Donations {id: $params.id}) + MATCH (donations:Donations) + WITH donations LIMIT 1 SET donations += $params SET donations.updatedAt = toString(datetime()) RETURN donations diff --git a/backend/src/schema/resolvers/donations.spec.js b/backend/src/schema/resolvers/donations.spec.js index a5264ee3a..9c62a7dda 100644 --- a/backend/src/schema/resolvers/donations.spec.js +++ b/backend/src/schema/resolvers/donations.spec.js @@ -10,8 +10,8 @@ const instance = getNeode() const driver = getDriver() const updateDonationsMutation = gql` - mutation($id: ID!, $goal: Int, $progress: Int) { - UpdateDonations(id: $id, goal: $goal, progress: $progress) { + mutation($goal: Int, $progress: Int) { + UpdateDonations(goal: $goal, progress: $progress) { goal progress createdAt @@ -48,7 +48,7 @@ describe('donations', () => { beforeEach(async () => { variables = {} - newlyCreatedDonations = await factory.create('Donations', { id: 'total-donations' }) + newlyCreatedDonations = await factory.create('Donations') }) afterEach(async () => { @@ -84,7 +84,7 @@ describe('donations', () => { describe('update donations', () => { beforeEach(() => { - variables = { id: 'total-donations', goal: 20000, progress: 3000 } + variables = { goal: 20000, progress: 3000 } }) describe('unauthenticated', () => { diff --git a/backend/src/schema/types/type/Donations.gql b/backend/src/schema/types/type/Donations.gql index 88e5edd2d..39cfe9b71 100644 --- a/backend/src/schema/types/type/Donations.gql +++ b/backend/src/schema/types/type/Donations.gql @@ -1,4 +1,5 @@ type Donations { + id: ID! goal: Int! progress: Int! createdAt: String @@ -10,5 +11,5 @@ type Query { } type Mutation { - UpdateDonations(id: ID!, goal: Int, progress: Int): Donations + UpdateDonations(goal: Int, progress: Int): Donations } \ No newline at end of file