switched to graphql to create a payment.

This commit is contained in:
Bryce Covert
2018-05-14 09:30:01 -07:00
parent fd2164e8ba
commit bbd9f00f30
5 changed files with 85 additions and 14 deletions

View File

@@ -10,7 +10,7 @@
:from :invoices-checks))
(defn query [q]
(map data->fields (u/query q)))
(u/query q))
(defn get-all []
(query base-query))

View File

@@ -9,6 +9,7 @@
[auto-ap.db.vendors :as vendors]
[auto-ap.db.companies :as companies]
[auto-ap.db.checks :as checks]
[auto-ap.routes.checks :as rchecks]
[auto-ap.db.reminders :as reminders]
[auto-ap.db.invoices-checks :as invoices-checks]
[auto-ap.db.utils :as utils]
@@ -17,6 +18,7 @@
(:import
(clojure.lang IPersistentMap)))
(def integreat-schema
{
:objects
@@ -77,7 +79,13 @@
:count {:type 'Int}
:total {:type 'Int}
:start {:type 'Int}
:end {:type 'Int}}}}
:end {:type 'Int}}}
:check_result {:fields {:invoices {:type '(list :invoice)}
:pdf_url {:type 'String}}}
}
:queries
{:invoice_page {:type '(list :invoice_page)
:args {:imported {:type 'Boolean}
@@ -96,7 +104,12 @@
:company {:type '(list :company)
:resolve :get-company}
:vendor {:type '(list :vendor)
:resolve :get-vendor}}})
:resolve :get-vendor}}
:mutations
{:print_checks {:type :check_result
:args {:invoice_ids {:type '(list Int)}}
:resolve :mutation/print-checks}}})
(defn by [x kf]
(reduce
@@ -202,6 +215,11 @@
(->graphql
(vendors/get-all)))
(defn print-checks [context args value]
(->graphql
(rchecks/print-checks (:invoice_ids args))))
(def schema
(-> integreat-schema
(attach-resolvers {:get-invoice-page get-invoice-page
@@ -211,6 +229,7 @@
:get-invoices-checks get-invoices-checks
:get-check-by-id get-check-by-id
:get-company get-company
:mutation/print-checks print-checks
:get-vendor get-vendor})
schema/compile))

View File

@@ -185,6 +185,34 @@
:invoices (map :id invoices)}))
(defn print-checks [invoice-ids]
(let [invoices (invoices/get-multi invoice-ids)
companies (into {}
(map (fn [c] [(:id c) c])
(companies/get-all)))
vendors (into {}
(map (fn [v] [(:id v) v])
(vendors/get-all)))
invoices-grouped-by-vendor (group-by :vendor-id invoices)
checks (-> (for [[vendor-id invoices] invoices-grouped-by-vendor]
[invoices (checks/insert! (check-for-invoices invoices vendor-id vendors companies))])
doall)
invoice-checks (invoices-checks/insert-multi!
(mapcat
(fn [[invoices check]]
(map
(fn [i]
{:invoice-id (:id i)
:check-id (:id check)
:amount (:total i)})
invoices))
checks)) ]
(make-pdfs (map second checks))
{:invoices (mapcat first checks)
:pdf-url (merge-pdfs (map (comp :s3-key second) checks))}))
(defroutes routes
(wrap-routes
(context "/checks" []