yodlee merchant or description
This commit is contained in:
@@ -50,7 +50,7 @@
|
|||||||
|
|
||||||
true
|
true
|
||||||
(merge-query {:query {:find ['?e]
|
(merge-query {:query {:find ['?e]
|
||||||
:where ['[?e :transaction-rule/description]]}}))]
|
:where ['[?e :transaction-rule/transaction-approval-status]]}}))]
|
||||||
|
|
||||||
|
|
||||||
(cond->> query
|
(cond->> query
|
||||||
@@ -82,5 +82,5 @@
|
|||||||
(mapv first
|
(mapv first
|
||||||
(d/query {:query {:find [(list 'pull '?e default-read )]
|
(d/query {:query {:find [(list 'pull '?e default-read )]
|
||||||
:in ['$]
|
:in ['$]
|
||||||
:where ['[?e :transaction-rule/description]]}
|
:where ['[?e :transaction-rule/transaction-approval-status]]}
|
||||||
:args [(d/db (d/connect uri))]})))
|
:args [(d/db (d/connect uri))]})))
|
||||||
|
|||||||
@@ -4,9 +4,10 @@
|
|||||||
[datomic.api :as d]
|
[datomic.api :as d]
|
||||||
[auto-ap.datomic :refer [remove-nils uri merge-query]]
|
[auto-ap.datomic :refer [remove-nils uri merge-query]]
|
||||||
[auto-ap.utils :refer [dollars=]]
|
[auto-ap.utils :refer [dollars=]]
|
||||||
[auto-ap.graphql.utils :refer [->graphql <-graphql limited-clients assert-admin result->page]]
|
[auto-ap.graphql.utils :refer [->graphql <-graphql limited-clients assert-admin result->page snake->kebab]]
|
||||||
[clj-time.coerce :as c]
|
[clj-time.coerce :as c]
|
||||||
[clojure.set :as set])
|
[clojure.set :as set]
|
||||||
|
[clojure.string :as str])
|
||||||
(:import [java.time.temporal ChronoField]))
|
(:import [java.time.temporal ChronoField]))
|
||||||
|
|
||||||
(defn ident->enum-f [k]
|
(defn ident->enum-f [k]
|
||||||
@@ -40,12 +41,14 @@
|
|||||||
#_(assert-admin (:id context))
|
#_(assert-admin (:id context))
|
||||||
(let [existing-transaction (tr/get-by-id id)
|
(let [existing-transaction (tr/get-by-id id)
|
||||||
deleted (deleted-accounts existing-transaction accounts)
|
deleted (deleted-accounts existing-transaction accounts)
|
||||||
_ (println existing-transaction)
|
|
||||||
_ (println "DELETING" deleted)
|
|
||||||
account-total (reduce + 0 (map (fn [x] (:percentage x)) accounts))
|
account-total (reduce + 0 (map (fn [x] (:percentage x)) accounts))
|
||||||
_ (when-not (dollars= 1.0 account-total)
|
_ (when-not (dollars= 1.0 account-total)
|
||||||
(let [error (str "Account total (" account-total ") does not reach 100%")]
|
(let [error (str "Account total (" account-total ") does not reach 100%")]
|
||||||
(throw (ex-info error {:validation-error error}))))
|
(throw (ex-info error {:validation-error error}))))
|
||||||
|
_ (when (and (str/blank? description)
|
||||||
|
(nil? yodlee_merchant_id))
|
||||||
|
(let [error (str "You must provide a description or a yodlee merchant")]
|
||||||
|
(throw (ex-info error {:validation-error error}))))
|
||||||
transaction [(remove-nils #:transaction-rule {:db/id (if id
|
transaction [(remove-nils #:transaction-rule {:db/id (if id
|
||||||
id
|
id
|
||||||
"transaction-rule")
|
"transaction-rule")
|
||||||
@@ -57,9 +60,15 @@
|
|||||||
:amount-lte amount_lte
|
:amount-lte amount_lte
|
||||||
:amount-gte amount_gte
|
:amount-gte amount_gte
|
||||||
:vendor vendor_id
|
:vendor vendor_id
|
||||||
:transaction-approval-status (keyword "transaction-approval-status" (name (<-graphql transaction_approval_status)))
|
:transaction-approval-status
|
||||||
|
(some->> transaction_approval_status
|
||||||
|
name
|
||||||
|
snake->kebab
|
||||||
|
(keyword "transaction-approval-status"))
|
||||||
:accounts (map transaction-rule-account->entity accounts)})]
|
:accounts (map transaction-rule-account->entity accounts)})]
|
||||||
|
|
||||||
|
_ (println transaction)
|
||||||
|
|
||||||
transaction (into transaction
|
transaction (into transaction
|
||||||
(map (fn [d]
|
(map (fn [d]
|
||||||
[:db/retract id :transaction-rule/accounts d])
|
[:db/retract id :transaction-rule/accounts d])
|
||||||
|
|||||||
@@ -127,7 +127,6 @@
|
|||||||
:transaction-rule/amount-gte :transaction-rule/amount-lte
|
:transaction-rule/amount-gte :transaction-rule/amount-lte
|
||||||
:transaction-rule/client :transaction-rule/bank-account
|
:transaction-rule/client :transaction-rule/bank-account
|
||||||
:transaction-rule/yodlee-merchant]} ]
|
:transaction-rule/yodlee-merchant]} ]
|
||||||
(println transaction description)
|
|
||||||
(let [transaction-dom (some-> transaction
|
(let [transaction-dom (some-> transaction
|
||||||
:transaction/date
|
:transaction/date
|
||||||
.toInstant
|
.toInstant
|
||||||
@@ -154,8 +153,8 @@
|
|||||||
(:db/id client))
|
(:db/id client))
|
||||||
true)
|
true)
|
||||||
(if yodlee-merchant
|
(if yodlee-merchant
|
||||||
(= (:transaction/yodlee-merchant transaction)
|
(= (:yodlee-merchant/yodlee-id (:transaction/yodlee-merchant transaction))
|
||||||
(:db/id yodlee-merchant))
|
(:yodlee-merchant/yodlee-id yodlee-merchant))
|
||||||
true)
|
true)
|
||||||
(if bank-account
|
(if bank-account
|
||||||
(= (:transaction/bank-account transaction)
|
(= (:transaction/bank-account transaction)
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
(ns auto-ap.entities.transaction-rule
|
(ns auto-ap.entities.transaction-rule
|
||||||
(:require [clojure.spec.alpha :as s]))
|
(:require [clojure.spec.alpha :as s]
|
||||||
|
[clojure.string :as str]))
|
||||||
|
|
||||||
(s/def ::client (s/nilable map?))
|
(s/def ::client (s/nilable map?))
|
||||||
(s/def ::description (s/nilable string?))
|
(s/def ::description (s/nilable string?))
|
||||||
@@ -7,8 +8,22 @@
|
|||||||
(s/def ::amount-lte (s/nilable double?))
|
(s/def ::amount-lte (s/nilable double?))
|
||||||
(s/def ::dom-gte (s/nilable int?))
|
(s/def ::dom-gte (s/nilable int?))
|
||||||
(s/def ::dom-lte (s/nilable int?))
|
(s/def ::dom-lte (s/nilable int?))
|
||||||
(s/def ::note (s/nilable string?))
|
(s/def ::note (s/and string?
|
||||||
|
#(not (str/blank? %))))
|
||||||
(s/def ::bank-account (s/nilable map?))
|
(s/def ::bank-account (s/nilable map?))
|
||||||
(s/def ::vendor (s/nilable map?))
|
(s/def ::vendor (s/nilable map?))
|
||||||
|
(s/def ::yodlee-merchant (s/nilable map?))
|
||||||
|
|
||||||
(s/def ::transaction-rule (s/keys :req-un [::client ::description ::amount-gte ::amount-lte ::dom-gte ::dom-lte ::note ::bank-account ::vendor]))
|
(s/def ::transaction-rule (s/and (s/keys :req-un [::client
|
||||||
|
::description
|
||||||
|
::amount-gte
|
||||||
|
::amount-lte
|
||||||
|
::dom-gte
|
||||||
|
::dom-lte
|
||||||
|
::note
|
||||||
|
::bank-account
|
||||||
|
::vendor
|
||||||
|
::yodlee-merchant])
|
||||||
|
|
||||||
|
(s/or :description-required #(not (str/blank? (:description %)))
|
||||||
|
:description-required #(not (nil? (:yodlee-merchant %))))))
|
||||||
|
|||||||
@@ -52,6 +52,15 @@
|
|||||||
:location "B"}]}}
|
:location "B"}]}}
|
||||||
[:id ]])}]})]
|
[:id ]])}]})]
|
||||||
(is (thrown? clojure.lang.ExceptionInfo (sut/query nil q)))))
|
(is (thrown? clojure.lang.ExceptionInfo (sut/query nil q)))))
|
||||||
|
(testing "It should reject rules that are missing both description and merchant"
|
||||||
|
(let [q (v/graphql-query {:venia/operation {:operation/type :mutation
|
||||||
|
:operation/name "UpsertTransactionRule"}
|
||||||
|
:venia/queries [{:query/data (sut/->graphql [:upsert-transaction-rule
|
||||||
|
{:transaction-rule {:accounts [{:account-id account-id
|
||||||
|
:percentage "1.0"
|
||||||
|
:location "B"}]}}
|
||||||
|
[:id ]])}]})]
|
||||||
|
(is (thrown? clojure.lang.ExceptionInfo (sut/query nil q)))))
|
||||||
(testing "it should add rules"
|
(testing "it should add rules"
|
||||||
(let [q (v/graphql-query {:venia/operation {:operation/type :mutation
|
(let [q (v/graphql-query {:venia/operation {:operation/type :mutation
|
||||||
:operation/name "UpsertTransactionRule"}
|
:operation/name "UpsertTransactionRule"}
|
||||||
|
|||||||
Reference in New Issue
Block a user