app/controllers/static_pages_controller.rb
def job_success
    jobId = params[:jobId]
    query = """
query MyQuery {
  jobs(where: {id: {_eq: #{jobId}}, emailedConfirmation: {_eq: false}}) {
    contactEmail
    contactName
    token
  }
}"""

    resp  = run_graphql_query(query)

    # Ruby is great.
    data = resp["data"] || {}
    jobs = data["jobs"] || []

    if jobs.length == 1
      job = jobs[0]

      # Send the email
      JobMailer.job_notification(job["contactEmail"], job["contactName"], job["token"]).deliver_now

      # Run the 'update' mutation
      q = """
mutation MyMutation {
  update_jobs(
    where: {id: {_eq: #{jobId}}},
    _set: {emailedConfirmation: true}) {
    affected_rows
  }
}
"""
      resp = run_graphql_query(q)
    end
  end
# Only send a confirmation email if it hasn't been sent yet.
Only send a confirmation email if it hasn't been sent yet.
Only send a confirmation email if it hasn ' t been sent yet .
def job_success
    jobId = params[:jobId]
    query = """
query MyQuery {
  jobs(where: {id: {_eq: #{jobId}}, emailedConfirmation: {_eq: false}}) {
    contactEmail
    contactName
    token
  }
}"""
    resp  = run_graphql_query(query)
    data = resp["data"] || {}
    jobs = data["jobs"] || []
    if jobs.length == 1
      job = jobs[0]
      JobMailer.job_notification(job["contactEmail"], job["contactName"], job["token"]).deliver_now
      q = """
mutation MyMutation {
  update_jobs(
    where: {id: {_eq: #{jobId}}},
    _set: {emailedConfirmation: true}) {
    affected_rows
  }
}
"""
      resp = run_graphql_query(q)
    end
  end
def job_success jobId = params [ :jobId ] query = "" "
query MyQuery {
  jobs(where: {id: {_eq: #{jobId}}, emailedConfirmation: {_eq: false}}) {
    contactEmail
    contactName
    token
  }
}" "" resp = run_graphql_query ( query ) data = resp [ "data" ] || { } jobs = data [ "jobs" ] || [ ] if jobs . length == 1 job = jobs [ 0 ] JobMailer . job_notification ( job [ "contactEmail" ] , job [ "contactName" ] , job [ "token" ] ) . deliver_now q = "" "
mutation MyMutation {
  update_jobs(
    where: {id: {_eq: #{jobId}}},
    _set: {emailedConfirmation: true}) {
    affected_rows
  }
}
" "" resp = run_graphql_query ( q ) end end
Only send a confirmation email if it hasn't been sent yet.
Only send a confirmation email if it hasn ' t been sent yet .
# Ruby is great. # Send the email # Run the 'update' mutation