Preventing bad imports
This commit is contained in:
@@ -448,19 +448,23 @@
|
||||
(map #(str/split % #"\t"))
|
||||
(map #(into {} (filter identity (map (fn [c k] [k c] ) % columns))))
|
||||
(map (parse-or-error :amount parse-amount))
|
||||
(map (parse-or-error :date parse-date)))
|
||||
(map (parse-or-error :date parse-date))
|
||||
(map (fn [{:keys [bank-account-code] :as row}]
|
||||
(if-let [bank-account-id (:db/id (all-bank-accounts bank-account-code))]
|
||||
(assoc row :bank-account-id bank-account-id)
|
||||
(update row :errors conj {:info (str "Cannot find bank by code " bank-account-code)
|
||||
:details (str "Cannot find bank by code " bank-account-code)}))))
|
||||
(map (fn [{:keys [client-code] :as row}]
|
||||
(if-let [client-id (:db/id (all-clients client-code))]
|
||||
(assoc row :client-id client-id)
|
||||
(update row :errors conj {:info (str "Cannot find client by code " client-code)
|
||||
:details (str "Cannot find client by code " client-code)})))))
|
||||
error-rows (filter :errors rows)
|
||||
_ (log/info "Importing " (count rows) "raw transactions")
|
||||
raw-transactions (vec (->> rows
|
||||
(filter #(not (seq (:errors %))) )
|
||||
(map (fn [{:keys [description-original client-code status high-level-category amount bank-account-code date]}]
|
||||
{:description-original description-original
|
||||
:date date
|
||||
:status status
|
||||
:high-level-category high-level-category
|
||||
:amount amount
|
||||
:client-id (:db/id (all-clients client-code))
|
||||
:bank-account-id (:db/id (all-bank-accounts bank-account-code))}))))]
|
||||
(map (fn [row]
|
||||
(select-keys row [:description-original :client-code :status :high-level-category :amount :bank-account-id :date])))))]
|
||||
|
||||
(manual-import raw-transactions)
|
||||
{:status 200
|
||||
|
||||
@@ -133,7 +133,12 @@
|
||||
{:id ::manual-import
|
||||
:events #{::manual/import-completed}
|
||||
:event-fn (fn [[_ {:keys [imported errors] :as result}]]
|
||||
[::status/info ::manual-import (str "Successfully imported " imported " transactions")])}]}))
|
||||
[::status/info ::manual-import (str "Successfully imported " imported " transactions"
|
||||
|
||||
(when (seq errors)
|
||||
(str
|
||||
", " (count errors) " errors. "
|
||||
"Example: '" (str (:info (first (:errors (first errors))))) "'")))])}]}))
|
||||
|
||||
|
||||
(defn content []
|
||||
|
||||
Reference in New Issue
Block a user