reminders have been graphqld

This commit is contained in:
Bryce Covert
2018-04-13 20:46:27 -07:00
parent 431c2883e2
commit 5e14ecd005
4 changed files with 90 additions and 10 deletions

View File

@@ -8,6 +8,7 @@
[auto-ap.db.invoices :as invoices]
[auto-ap.db.vendors :as vendors]
[auto-ap.db.companies :as companies]
[auto-ap.db.reminders :as reminders]
[auto-ap.db.utils :as utils]
[clojure.walk :as walk]
[clojure.string :as str])
@@ -26,6 +27,16 @@
{:fields {:id {:type 'Int}
:name {:type 'String}
:invoice_reminder_schedule {:type 'String}}}
:reminder
{:fields {:id {:type 'Int}
:email {:type 'String}
:subject {:type 'String}
:body {:type 'String}
:scheduled {:type 'String}
:sent {:type 'String}
:vendor {:type :vendor
:resolve :get-vendor-for-invoice}}
}
:invoice
{:fields {:id {:type 'Int}
:total {:type 'String}
@@ -42,7 +53,13 @@
:count {:type 'Int}
:total {:type 'Int}
:start {:type 'Int}
:end {:type 'Int}}}}
:end {:type 'Int}}}
:reminder_page {:fields {:reminders {:type '(list :reminder)}
:count {:type 'Int}
:total {:type 'Int}
:start {:type 'Int}
:end {:type 'Int}}}}
:queries
{:invoice_page {:type '(list :invoice_page)
:args {:imported {:type 'Boolean}
@@ -52,6 +69,12 @@
:asc {:type 'Boolean}}
:resolve :get-invoice-page}
:reminder_page {:type '(list :reminder_page)
:args {:start {:type 'Int}
:sort_by {:type 'String}
:asc {:type 'Boolean}}
:resolve :get-reminder-page}
:company {:type '(list :company)
:resolve :get-company}
:vendor {:type '(list :vendor)
@@ -117,6 +140,22 @@
:start (:start args 0)
:end (+ (:start args 0) (count invoices))}] extra-context)))
(defn get-reminder-page [context args value]
(let [extra-context
(cond-> {}
(executor/selects-field? context :reminder/vendor) (assoc :vendor-cache (by (vendors/get-all) :id )))
reminders (map
->graphql
(reminders/get-graphql (<-graphql args)))
reminder-count (reminders/count-graphql (<-graphql args))]
(resolve/with-context
[{:reminders reminders
:total reminder-count
:count (count reminders)
:start (:start args 0)
:end (+ (:start args 0) (count reminders))}] extra-context)))
(defn get-vendor-for-invoice [context args value]
(->graphql
(if-let [vendor-cache (:vendor-cache context)]
@@ -140,6 +179,7 @@
(def schema
(-> integreat-schema
(attach-resolvers {:get-invoice-page get-invoice-page
:get-reminder-page get-reminder-page
:get-vendor-for-invoice get-vendor-for-invoice
:get-company-for-invoice get-company-for-invoice
:get-company get-company