From 5a1c907aab221a184e673d348b3d1e8cfeda3289 Mon Sep 17 00:00:00 2001 From: Lyna Date: Wed, 13 Nov 2024 18:42:30 +0100 Subject: [PATCH] improve cron-job code --- api/config/initializers/sidekiq.rb | 2 ++ api/jobs/set_costumer_id_job.rb | 2 +- api/modal/dwolla.rb | 3 ++- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/api/config/initializers/sidekiq.rb b/api/config/initializers/sidekiq.rb index a4c8e5e..348f060 100644 --- a/api/config/initializers/sidekiq.rb +++ b/api/config/initializers/sidekiq.rb @@ -1,3 +1,5 @@ +require 'dotenv' +Dotenv.load require 'sidekiq' require 'sidekiq-cron' require 'yaml' diff --git a/api/jobs/set_costumer_id_job.rb b/api/jobs/set_costumer_id_job.rb index 7c62d8d..48e82e6 100644 --- a/api/jobs/set_costumer_id_job.rb +++ b/api/jobs/set_costumer_id_job.rb @@ -12,7 +12,7 @@ def perform dwolla.init() costumers = dwolla.get_costomers() - costumers["_embedded"]["customers"].each do |customer| + costumers.each do |customer| user = ::User.find_by(email: customer["email"] ) user.update(dwolla_id: customer["id"] ) if user.present? end diff --git a/api/modal/dwolla.rb b/api/modal/dwolla.rb index df8728e..aaa71c5 100644 --- a/api/modal/dwolla.rb +++ b/api/modal/dwolla.rb @@ -16,7 +16,8 @@ def create_verifed_user(request_body) end def get_costomers - @@dwolla.get "customers" + response_body = @@dwolla.get "customers" + response_body["_embedded"]["customers"] end def get_costumer(request_body)