mirror of
https://github.com/IT4Change/Ocelot-Social.git
synced 2025-12-13 07:45:56 +00:00
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.
This commit is contained in:
parent
835a098731
commit
afb443ac0d
@ -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
|
||||
|
||||
@ -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', () => {
|
||||
|
||||
@ -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
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user