From f0fb70f193145e88222949fe1835ef7614ea3905 Mon Sep 17 00:00:00 2001 From: Bryce Covert Date: Fri, 1 Feb 2019 16:58:11 -0800 Subject: [PATCH] fixes, adding renames. --- src/clj/auto_ap/datomic/checks.clj | 3 +- src/clj/auto_ap/datomic/invoices.clj | 2 +- src/clj/auto_ap/datomic/migrate.clj | 2 + .../auto_ap/datomic/migrate/rename_codes.clj | 37 +++++++++++++++++++ src/clj/auto_ap/datomic/transactions.clj | 2 +- src/clj/auto_ap/graphql.clj | 1 + src/clj/auto_ap/routes/auth.clj | 24 ++++++++---- src/clj/auto_ap/routes/exports.clj | 2 +- 8 files changed, 61 insertions(+), 12 deletions(-) create mode 100644 src/clj/auto_ap/datomic/migrate/rename_codes.clj diff --git a/src/clj/auto_ap/datomic/checks.clj b/src/clj/auto_ap/datomic/checks.clj index f1e5a7b1..bb830014 100644 --- a/src/clj/auto_ap/datomic/checks.clj +++ b/src/clj/auto_ap/datomic/checks.clj @@ -23,7 +23,8 @@ (def default-read '(pull ?e [* {:invoice-payment/_payment [* {:invoice-payment/invoice [*]}]} {:payment/client [:client/name :db/id]} - {:payment/vendor [:vendor/name :db/id]} + {:payment/bank-account [*]} + {:payment/vendor [:vendor/name :vendor/default-expense-account :db/id {:vendor/primary-contact [*]} {:vendor/address [*]}]} {:payment/status [:db/ident]} {:payment/type [:db/ident]}])) diff --git a/src/clj/auto_ap/datomic/invoices.clj b/src/clj/auto_ap/datomic/invoices.clj index 58932a42..13c79f36 100644 --- a/src/clj/auto_ap/datomic/invoices.clj +++ b/src/clj/auto_ap/datomic/invoices.clj @@ -16,7 +16,7 @@ (def default-read '(pull ?e [* {:invoice/client [:client/name :db/id :client/locations]} - {:invoice/vendor [:vendor/name :db/id]} + {:invoice/vendor [* {:vendor/address [*]}]} {:invoice/status [:db/ident]} {:invoice-payment/_invoice [* {:invoice-payment/payment [* {:payment/status [*]} {:payment/bank-account [*]} diff --git a/src/clj/auto_ap/datomic/migrate.clj b/src/clj/auto_ap/datomic/migrate.clj index 7f0441bc..4fa38001 100644 --- a/src/clj/auto_ap/datomic/migrate.clj +++ b/src/clj/auto_ap/datomic/migrate.clj @@ -53,6 +53,8 @@ :auto-ap/add-client-codes {:txes-fn 'auto-ap.datomic.migrate.add-client-codes/add-client-codes :requires [:auto-ap/migrate-transactions]} :auto-ap/add-bank-account-codes-schema {:txes-fn 'auto-ap.datomic.migrate.add-bank-account-codes/add-bank-account-codes-schema :requires [:auto-ap/add-client-codes]} :auto-ap/add-bank-account-codes {:txes-fn 'auto-ap.datomic.migrate.add-bank-account-codes/add-bank-account-codes :requires [:auto-ap/add-bank-account-codes-schema]} + :auto-ap/add-nick-the-greek {:txes [[{:client/name "Nick the Greek" :client/code "NGAK" :client/locations ["MH"] :client/bank-accounts [{:bank-account/code "NGAK-0" :bank-account/type :bank-account-type/cash :bank-account/name "Cash"}]}]] :requires [:auto-ap/add-bank-account-codes]} + :auto-ap/rename-codes-3 {:txes-fn 'auto-ap.datomic.migrate.rename-codes/rename-1 :requires [:auto-ap/add-nick-the-greek]} }] (println "Conforming database...") (println (c/ensure-conforms conn norms-map)) diff --git a/src/clj/auto_ap/datomic/migrate/rename_codes.clj b/src/clj/auto_ap/datomic/migrate/rename_codes.clj new file mode 100644 index 00000000..48af019d --- /dev/null +++ b/src/clj/auto_ap/datomic/migrate/rename_codes.clj @@ -0,0 +1,37 @@ +(ns auto-ap.datomic.migrate.rename-codes + (:require [datomic.api :as d] + [auto-ap.datomic :refer [uri]] + [clojure.string :as str])) + +(defn rename [old-code new-code conn ] + (let [results (->> (d/query {:query {:find ['?e '?b '?bc] + :in ['$ '?old-code] + :where ['[?e :client/code ?old-code] + '[?e :client/bank-accounts ?b] + '[?b :bank-account/code ?bc]]} + :args [(d/db conn) old-code]}) + (group-by first)) + + #_#_[[id]] results] + (for [[id change] results + [_ ba-id ba-code] change] + [{:db/id id + :client/code new-code} + {:db/id ba-id + :bank-account/code (str/replace ba-code #"^.*-" (str new-code "-"))}]) + + #_[{:db/id id + :client/code new-code + #_#_:client/bank-accounts (map)}] + ) + ) + +(defn rename-1 [conn] + (apply concat [(rename "WE" "WME" (d/connect uri)) + (rename "HM" "HIM" (d/connect uri)) + (rename "BES" "SBE" (d/connect uri)) + (rename "BES" "SBE" (d/connect uri)) + (rename "ORA" "OMG" (d/connect uri)) + (rename "INT" "IGC" (d/connect uri)) + (rename "MV" "MVSC" (d/connect uri))])) + diff --git a/src/clj/auto_ap/datomic/transactions.clj b/src/clj/auto_ap/datomic/transactions.clj index dc069b95..225b937f 100644 --- a/src/clj/auto_ap/datomic/transactions.clj +++ b/src/clj/auto_ap/datomic/transactions.clj @@ -113,7 +113,7 @@ (defn graphql-results [ids db args] (->> (d/pull-many db '[* {:transaction/client [:client/name :db/id] - :transaction/bank-account [:bank-account/name :bank-account/yodlee-account-id]}] + :transaction/bank-account [:bank-account/name :bank-account/yodlee-account-id :db/id]}] ids) (map #(update % :transaction/date c/from-date)) (map #(update % :transaction/post-date c/from-date)) diff --git a/src/clj/auto_ap/graphql.clj b/src/clj/auto_ap/graphql.clj index 4eaedb63..e011215b 100644 --- a/src/clj/auto_ap/graphql.clj +++ b/src/clj/auto_ap/graphql.clj @@ -57,6 +57,7 @@ :check_number {:type 'Int} :name {:type 'String} :bank_code {:type 'String} + :routing {:type 'String} :bank_name {:type 'String} :yodlee_account_id {:type 'Int}}} :address diff --git a/src/clj/auto_ap/routes/auth.clj b/src/clj/auto_ap/routes/auth.clj index 772ec985..a958e8ac 100644 --- a/src/clj/auto_ap/routes/auth.clj +++ b/src/clj/auto_ap/routes/auth.clj @@ -9,6 +9,14 @@ (def google-client-id "264081895820-0nndcfo3pbtqf30sro82vgq5r27h8736.apps.googleusercontent.com") (def google-client-secret "OC-WemHurPXYpuIw5cT-B90g") +(defn make-api-token [] + (jwt/sign {:user "API" + :exp (time/plus (time/now) (time/days 700)) + :user/role "admin" + :user/name "API"} + (:jwt-secret env) + {:alg :hs512})) + (defroutes routes (GET "/oauth" {{:strs [code]} :query-params :keys [scheme] :as r {:strs [host]} :headers} (try @@ -37,14 +45,14 @@ ;; TODO - these namespaces are not being transmitted/deserialized properly (if (and token user) {:status 301 - :headers {"Location" (str "/?jwt=" (jwt/sign {:user (:name profile) - :exp (time/plus (time/now) (time/days 7)) - :user/clients (map (fn [c] - (dissoc c :client/bank-accounts ) - ) - (:user/clients user)) - :user/role (name (:user/role user)) - :user/name (:name profile)} + :headers {"Location" (str "/?jwt=" (jwt/sign (doto {:user (:name profile) + :exp (time/plus (time/now) (time/days 7)) + :user/clients (map (fn [c] + (dissoc c :client/bank-accounts )) + (:user/clients user)) + :user/role (name (:user/role user)) + :user/name (:name profile)} + println) (:jwt-secret env) {:alg :hs512}))}} {:status 401 diff --git a/src/clj/auto_ap/routes/exports.clj b/src/clj/auto_ap/routes/exports.clj index 38d3966d..74c983bb 100644 --- a/src/clj/auto_ap/routes/exports.clj +++ b/src/clj/auto_ap/routes/exports.clj @@ -57,7 +57,7 @@ (assert-admin identity) (let [[transactions] (d-transactions/get-graphql {:client-code (query-params "client-code") #_#_:original-id (Integer/parseInt (query-params "original")) - :limit Integer/MAX_VALUE}) + :count Integer/MAX_VALUE}) ] (map (comp ->graphql (fn [i] (-> i