From 3e8c359458537de14391d3c0e7686c2fa743cfe3 Mon Sep 17 00:00:00 2001 From: Bryce Covert Date: Thu, 11 Oct 2018 20:24:32 -0700 Subject: [PATCH 1/7] updates. --- src/clj/auto_ap/yodlee/core.clj | 43 ++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 12 deletions(-) diff --git a/src/clj/auto_ap/yodlee/core.clj b/src/clj/auto_ap/yodlee/core.clj index 225bc415..6c147577 100644 --- a/src/clj/auto_ap/yodlee/core.clj +++ b/src/clj/auto_ap/yodlee/core.clj @@ -92,18 +92,33 @@ (defn get-provider-accounts [] (let [cob-session (login-cobrand) user-session (login-user cob-session) - batch-size 100 - get-transaction-batch (fn [] - (-> (str (:yodlee-base-url env) "/providerAccounts") + batch-size 100] - (client/get {:headers (doto - (merge base-headers {"Authorization" (auth-header cob-session user-session)}) - println) - :as :json}) - :body - ))] + (-> (str (:yodlee-base-url env) "/providerAccounts") - (get-transaction-batch))) + (client/get {:headers (doto + (merge base-headers {"Authorization" (auth-header cob-session user-session)}) + println) + :as :json}) + :body + :providerAccount + ))) + + + +(defn get-provider-account [id] + (let [cob-session (login-cobrand) + user-session (login-user cob-session) + batch-size 100] + + (-> (str (:yodlee-base-url env) "/providerAccounts/" id) + + (client/get {:headers (doto + (merge base-headers {"Authorization" (auth-header cob-session user-session)}) + println) + :as :json}) + :body + :providerAccount))) (defn update-provider-account [pa] (let [cob-session (login-cobrand) @@ -118,12 +133,16 @@ :body "{\"dataSetName\": [\"BASIC_AGG_DATA\"]}" :as :json})))) -(defn get-specific-transactions [] +(defn update-yodlee [id] + (update-provider-account (:providerAccountId (first (filter #(= (:id %) id) (get-accounts))))) + (get-provider-account (:providerAccountId (first (filter #(= (:id %) id) (get-accounts)))))) + +(defn get-specific-transactions [account] (let [cob-session (login-cobrand) user-session (login-user cob-session) batch-size 100 get-transaction-batch (fn [skip] - (-> (str (:yodlee-base-url env) "/transactions?top=" batch-size "&skip=" skip "&accountId=16422358") + (-> (str (:yodlee-base-url env) "/transactions?top=" batch-size "&skip=" skip "&accountId=" account) (doto println) (client/get {:headers (doto From 2401c5c2274aafc682717e884ef10106daf91e2d Mon Sep 17 00:00:00 2001 From: BC Date: Thu, 25 Oct 2018 19:01:45 -0700 Subject: [PATCH 2/7] allow negative invoice. --- src/cljc/auto_ap/entities/shared.cljc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cljc/auto_ap/entities/shared.cljc b/src/cljc/auto_ap/entities/shared.cljc index d83cea24..b2363b46 100644 --- a/src/cljc/auto_ap/entities/shared.cljc +++ b/src/cljc/auto_ap/entities/shared.cljc @@ -3,7 +3,7 @@ [clojure.string :as str])) (def date-regex #"[0-9]{4}-[0-9]{1,2}-[0-9]{1,2}") -(def money-regex #"[0-9]+(\.[0-9]{1,2})?$") +(def money-regex #"\-?[0-9]+(\.[0-9]{1,2})?$") (s/def ::identifier (s/nilable string?)) (s/def ::date (s/and string? #(re-matches date-regex %))) From d1db270f4eabb21ceb243d3cfa4d0fb9c0639390 Mon Sep 17 00:00:00 2001 From: BC Date: Thu, 25 Oct 2018 19:11:26 -0700 Subject: [PATCH 3/7] allowing saving after saving. --- src/cljc/auto_ap/entities/vendors.cljc | 17 ++++++++--------- .../auto_ap/views/components/vendor_dialog.cljs | 3 ++- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/cljc/auto_ap/entities/vendors.cljc b/src/cljc/auto_ap/entities/vendors.cljc index b0805117..bacdc4ab 100644 --- a/src/cljc/auto_ap/entities/vendors.cljc +++ b/src/cljc/auto_ap/entities/vendors.cljc @@ -5,8 +5,7 @@ (def email-regex #"^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,63}$") (s/def ::id int) -(s/def ::identifier (s/nilable string?)) -(s/def ::required-identifier (s/and string? +(s/def ::identifier (s/nilable string?)) (s/def ::required-identifier (s/and string? #(not (str/blank? %)))) (s/def ::name ::required-identifier) @@ -17,14 +16,14 @@ (s/def ::phone (s/nilable string?)) (s/def ::invoice-reminder-schedule (s/nilable #{"Weekly" "Never" nil})) -(s/def ::primary-contact ::identifier) -(s/def ::primary-email ::email) -(s/def ::primary-phone ::phone) +(s/def ::primary-contact (s/nilable ::identifier)) +(s/def ::primary-email (s/nilable ::email)) +(s/def ::primary-phone (s/nilable ::phone)) -(s/def ::secondary-contact ::identifier) -(s/def ::secondary-email ::email) -(s/def ::secondary-phone ::phone) -(s/def ::address ::address/address) +(s/def ::secondary-contact (s/nilable ::identifier)) +(s/def ::secondary-email (s/nilable ::email)) +(s/def ::secondary-phone (s/nilable ::phone)) +(s/def ::address (s/nilable ::address/address)) (s/def ::default-expense-account int?) (s/def ::code (s/nilable string?)) diff --git a/src/cljs/auto_ap/views/components/vendor_dialog.cljs b/src/cljs/auto_ap/views/components/vendor_dialog.cljs index fea46601..5ca766e6 100644 --- a/src/cljs/auto_ap/views/components/vendor_dialog.cljs +++ b/src/cljs/auto_ap/views/components/vendor_dialog.cljs @@ -11,6 +11,7 @@ [auto-ap.subs :as subs])) (defn vendor-dialog [{:keys [vendor save-event change-event id] {:keys [name]} :vendor}] + (let [companies-by-id @(re-frame/subscribe [::subs/companies-by-id])] [action-modal {:id id :title [:span (if (:id vendor) @@ -23,7 +24,7 @@ :save-event save-event :can-submit? (s/valid? ::entity/vendor vendor)} - (doto (s/explain ::entity/vendor vendor) println) + [horizontal-field [:label.label "Name"] From 2b3898f4444126bacd9720a9a26dc311e30f58e5 Mon Sep 17 00:00:00 2001 From: BC Date: Thu, 25 Oct 2018 20:10:13 -0700 Subject: [PATCH 4/7] Adding info. --- src/cljs/auto_ap/views/pages/admin/yodlee.cljs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/cljs/auto_ap/views/pages/admin/yodlee.cljs b/src/cljs/auto_ap/views/pages/admin/yodlee.cljs index 5cc5e558..221975a7 100644 --- a/src/cljs/auto_ap/views/pages/admin/yodlee.cljs +++ b/src/cljs/auto_ap/views/pages/admin/yodlee.cljs @@ -2,6 +2,7 @@ (:require-macros [cljs.core.async.macros :refer [go]]) (:require [re-frame.core :as re-frame] [reagent.core :as reagent] + [clojure.string :as str] [auto-ap.subs :as subs] [auto-ap.events.admin.companies :as events] [auto-ap.entities.companies :as entity] @@ -106,7 +107,8 @@ [:tr [:th "Account Name"] [:th "Account Number"] - [:th "Yodlee Account Number"]]] + [:th "Yodlee Account Number"] + [:th "Yodlee Status"]]] (if @(re-frame/subscribe [::accounts-loading?]) [:tr [:td {:col-span "3"} "Loading..."] ] @@ -114,7 +116,9 @@ [:tr [:td (:accountName account)] [:td (:accountNumber account)] - [:td (:id account)]]))]]) + [:td (:id account)] + [:td (str/join ", " (map :additionalStatus (:dataset account)))] + ]))]]) (defn admin-yodlee-page [] From 8478011b8cb60b8ccd5128f2016f185763298dc4 Mon Sep 17 00:00:00 2001 From: BC Date: Thu, 25 Oct 2018 20:30:26 -0700 Subject: [PATCH 5/7] updates. --- src/clj/auto_ap/routes/yodlee.clj | 8 +++++++- src/cljs/auto_ap/views/pages/admin/yodlee.cljs | 16 ++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/clj/auto_ap/routes/yodlee.clj b/src/clj/auto_ap/routes/yodlee.clj index 56d34e88..97ec09b8 100644 --- a/src/clj/auto_ap/routes/yodlee.clj +++ b/src/clj/auto_ap/routes/yodlee.clj @@ -36,5 +36,11 @@ (let [[session token] (yodlee/get-access-token)] {:status 200 :headers {"Content-Type" "application/edn"} - :body (pr-str (yodlee/get-accounts)) }))) + :body (pr-str (yodlee/get-accounts)) })) + (POST "/accounts/:id" {:keys [query-params identity] {:keys [id]} :route-params :as request} + (assert-admin identity) + (let [[session token] (yodlee/get-access-token)] + {:status 200 + :headers {"Content-Type" "application/edn"} + :body (pr-str (yodlee/update-yodlee (Long/parseLong id))) }))) wrap-secure)) diff --git a/src/cljs/auto_ap/views/pages/admin/yodlee.cljs b/src/cljs/auto_ap/views/pages/admin/yodlee.cljs index 221975a7..fd929e06 100644 --- a/src/cljs/auto_ap/views/pages/admin/yodlee.cljs +++ b/src/cljs/auto_ap/views/pages/admin/yodlee.cljs @@ -57,6 +57,18 @@ :on-success [::got-accounts] :on-error [::save-error]}})) + +(re-frame/reg-event-fx + ::kick + (fn [{:keys [db]} [_ id]] + {:db (assoc-in db [::yodlee] {:accounts-loading? true}) + :http {:token (:user db) + :method :post + :headers {"Content-Type" "application/edn"} + :uri (str "/api/yodlee/accounts/" id) + :on-success [::mounted] + :on-error [::save-error]}})) + (re-frame/reg-event-fx ::got-accounts (fn [{:keys [db]} [_ accounts]] @@ -108,7 +120,9 @@ [:th "Account Name"] [:th "Account Number"] [:th "Yodlee Account Number"] + [:th "Yodlee Last updated"] [:th "Yodlee Status"]]] + (if @(re-frame/subscribe [::accounts-loading?]) [:tr [:td {:col-span "3"} "Loading..."] ] @@ -117,7 +131,9 @@ [:td (:accountName account)] [:td (:accountNumber account)] [:td (:id account)] + [:td (str/join ", " (map :lastUpdated (:dataset account)))] [:td (str/join ", " (map :additionalStatus (:dataset account)))] + [:td [:button.button.is-success {:on-click (dispatch-event [::kick (:id account)] )} "Kick." ]] ]))]]) From 8c1826f0222aa4bc79dd151c596f98517c612b3b Mon Sep 17 00:00:00 2001 From: BC Date: Thu, 25 Oct 2018 21:08:16 -0700 Subject: [PATCH 6/7] fixing kicking. --- .../auto_ap/views/pages/admin/yodlee.cljs | 32 +++++++++++++++---- 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/src/cljs/auto_ap/views/pages/admin/yodlee.cljs b/src/cljs/auto_ap/views/pages/admin/yodlee.cljs index fd929e06..ad95a5f4 100644 --- a/src/cljs/auto_ap/views/pages/admin/yodlee.cljs +++ b/src/cljs/auto_ap/views/pages/admin/yodlee.cljs @@ -57,6 +57,18 @@ :on-success [::got-accounts] :on-error [::save-error]}})) +(re-frame/reg-event-fx + ::kicked + (fn [{:keys [db]} [_ id state]] + {:db (update-in db [::yodlee :accounts] + (fn [as] + (map (fn [a] + (if (= (:id a) id) + (assoc a :status state) + a)) + as))) + })) + (re-frame/reg-event-fx ::kick @@ -66,8 +78,8 @@ :method :post :headers {"Content-Type" "application/edn"} :uri (str "/api/yodlee/accounts/" id) - :on-success [::mounted] - :on-error [::save-error]}})) + :on-success [::kicked id :kicking] + :on-error [::kicked id :errored]}})) (re-frame/reg-event-fx ::got-accounts @@ -121,10 +133,11 @@ [:th "Account Number"] [:th "Yodlee Account Number"] [:th "Yodlee Last updated"] - [:th "Yodlee Status"]]] + [:th "Yodlee Status"] + [:th]]] (if @(re-frame/subscribe [::accounts-loading?]) - [:tr [:td {:col-span "3"} "Loading..."] + [:tr [:td {:col-span "6"} "Loading..."] ] (for [account @(re-frame/subscribe [::accounts])] [:tr @@ -133,8 +146,15 @@ [:td (:id account)] [:td (str/join ", " (map :lastUpdated (:dataset account)))] [:td (str/join ", " (map :additionalStatus (:dataset account)))] - [:td [:button.button.is-success {:on-click (dispatch-event [::kick (:id account)] )} "Kick." ]] - ]))]]) + [:td + (cond (= (:status account) :kicking) + [:button.button.is-success.is-loading {:disabled "disabled"} "Kick."] + + (= (:status account) :error) + [:button.button.is-error.is-loading {:disabled "disabled"} "Error."] + + :else + [:button.button.is-success {:on-click (dispatch-event [::kick (:id account)] )} "Kick." ])]]))]]) (defn admin-yodlee-page [] From 690228ee94bdec08272f23d72867429d0b35e9a7 Mon Sep 17 00:00:00 2001 From: BC Date: Thu, 25 Oct 2018 21:11:38 -0700 Subject: [PATCH 7/7] fixing kicking. --- src/cljs/auto_ap/views/pages/admin/yodlee.cljs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/cljs/auto_ap/views/pages/admin/yodlee.cljs b/src/cljs/auto_ap/views/pages/admin/yodlee.cljs index ad95a5f4..361859f2 100644 --- a/src/cljs/auto_ap/views/pages/admin/yodlee.cljs +++ b/src/cljs/auto_ap/views/pages/admin/yodlee.cljs @@ -66,15 +66,13 @@ (if (= (:id a) id) (assoc a :status state) a)) - as))) - })) + as)))})) (re-frame/reg-event-fx ::kick (fn [{:keys [db]} [_ id]] - {:db (assoc-in db [::yodlee] {:accounts-loading? true}) - :http {:token (:user db) + {:http {:token (:user db) :method :post :headers {"Content-Type" "application/edn"} :uri (str "/api/yodlee/accounts/" id)