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