pagination.
This commit is contained in:
@@ -71,12 +71,23 @@
|
||||
q)))
|
||||
|
||||
|
||||
(defn get-graphql [{:keys [imported company-id sort-by asc]}]
|
||||
|
||||
(defn base-graphql [{:keys [imported company-id]}]
|
||||
(cond-> base-query
|
||||
(not (nil? imported)) (helpers/merge-where [:= :imported imported])
|
||||
(not (nil? company-id)) (helpers/merge-where [:= :company-id company-id])
|
||||
))
|
||||
|
||||
(defn get-graphql [{:keys [start sort-by asc] :as args}]
|
||||
(query
|
||||
(cond-> base-query
|
||||
(not (nil? imported)) (helpers/merge-where [:= :imported imported])
|
||||
(not (nil? company-id)) (helpers/merge-where [:= :company-id company-id])
|
||||
(not (nil? sort-by) ) (add-sort-by sort-by asc))))
|
||||
(cond-> (base-graphql args)
|
||||
(not (nil? sort-by) ) (add-sort-by sort-by asc)
|
||||
true (assoc :limit 20)
|
||||
start (assoc :offset start))))
|
||||
|
||||
(defn count-graphql [args]
|
||||
(:count (first (query
|
||||
(assoc (base-graphql args) :select [:%count.*])))))
|
||||
|
||||
(defn import [parsed-invoices companies vendors]
|
||||
(insert-multi!
|
||||
|
||||
@@ -36,15 +36,22 @@
|
||||
|
||||
:resolve :get-vendor-for-invoice}
|
||||
:company {:type :company
|
||||
:resolve :get-company-for-invoice}}}}
|
||||
:resolve :get-company-for-invoice}}}
|
||||
|
||||
:invoice_page {:fields {:invoices {:type '(list :invoice)}
|
||||
:count {:type 'Int}
|
||||
:total {:type 'Int}
|
||||
:start {:type 'Int}
|
||||
:end {:type 'Int}}}}
|
||||
:queries
|
||||
{:invoice {:type '(list :invoice)
|
||||
:args {:imported {:type 'Boolean}
|
||||
:company_id {:type 'Int}
|
||||
:sort_by {:type 'String}
|
||||
:asc {:type 'Boolean}}
|
||||
|
||||
:resolve :get-invoice}
|
||||
{:invoice_page {:type '(list :invoice_page)
|
||||
:args {:imported {:type 'Boolean}
|
||||
:company_id {:type 'Int}
|
||||
:start {:type 'Int}
|
||||
:sort_by {:type 'String}
|
||||
:asc {:type 'Boolean}}
|
||||
|
||||
:resolve :get-invoice-page}
|
||||
:company {:type '(list :company)
|
||||
:resolve :get-company}
|
||||
:vendor {:type '(list :vendor)
|
||||
@@ -93,17 +100,22 @@
|
||||
node))
|
||||
m))
|
||||
|
||||
(defn get-invoice [context args value]
|
||||
|
||||
(println (<-graphql args))
|
||||
(defn get-invoice-page [context args value]
|
||||
(let [extra-context
|
||||
(cond-> {}
|
||||
(executor/selects-field? context :invoice/vendor) (assoc :vendor-cache (by (vendors/get-all) :id ))
|
||||
(executor/selects-field? context :invoice/company) (assoc :company-cache (by (companies/get-all) :id )))]
|
||||
(executor/selects-field? context :invoice/company) (assoc :company-cache (by (companies/get-all) :id )))
|
||||
|
||||
invoices (map
|
||||
->graphql
|
||||
(invoices/get-graphql (<-graphql args)))
|
||||
invoice-count (invoices/count-graphql (<-graphql args))]
|
||||
(resolve/with-context
|
||||
(map
|
||||
->graphql
|
||||
(invoices/get-graphql (<-graphql args))) extra-context)))
|
||||
[{:invoices invoices
|
||||
:total invoice-count
|
||||
:count (count invoices)
|
||||
:start (:start args 0)
|
||||
:end (+ (:start args 0) (count invoices))}] extra-context)))
|
||||
|
||||
(defn get-vendor-for-invoice [context args value]
|
||||
(->graphql
|
||||
@@ -127,7 +139,7 @@
|
||||
|
||||
(def schema
|
||||
(-> integreat-schema
|
||||
(attach-resolvers {:get-invoice get-invoice
|
||||
(attach-resolvers {:get-invoice-page get-invoice-page
|
||||
:get-vendor-for-invoice get-vendor-for-invoice
|
||||
:get-company-for-invoice get-company-for-invoice
|
||||
:get-company get-company
|
||||
|
||||
Reference in New Issue
Block a user