all columns available.

This commit is contained in:
BC
2018-07-05 23:41:50 -07:00
parent 07d7a8ff51
commit de1ead6b9e
5 changed files with 101 additions and 12 deletions

View File

@@ -0,0 +1,4 @@
-- 1530859118 DOWN add-indexes
drop index IX_invoices_expense_accounts__invoice_id ;
drop index IX_invoices_checks__invoice_id ;

View File

@@ -0,0 +1,3 @@
-- 1530859118 UP add-indexes
create index IX_invoices_expense_accounts__invoice_id ON invoices_expense_accounts (invoice_id);
create index IX_invoices_checks__invoice_id ON invoices_checks (invoice_id);

View File

@@ -19,6 +19,11 @@
(query (-> base-query (query (-> base-query
(helpers/merge-where [:= :invoice-id id])))) (helpers/merge-where [:= :invoice-id id]))))
(defn get-for-check-id [id]
(query (-> base-query
(helpers/merge-where [:= :check-id id]))))
(defn get-sum-by-invoice [id] (defn get-sum-by-invoice [id]
(:sum (first (query (-> (helpers/select :%sum.amount) (:sum (first (query (-> (helpers/select :%sum.amount)
(helpers/from :invoices-checks) (helpers/from :invoices-checks)

View File

@@ -73,6 +73,8 @@
} }
} }
:check {:fields {:id {:type 'Int} :check {:fields {:id {:type 'Int}
:amount {:type 'String} :amount {:type 'String}
:vendor {:type :vendor :vendor {:type :vendor
@@ -80,9 +82,15 @@
:company {:type :company :company {:type :company
:resolve :get-company-for-check} :resolve :get-company-for-check}
:date {:type 'String} :date {:type 'String}
:bank_account {:type :bank_account
:resolve :bank-account-for-check}
:memo {:type 'String}
:s3_url {:type 'String} :s3_url {:type 'String}
:check_number {:type 'Int} :check_number {:type 'Int}
:status {:type 'String}}} :status {:type 'String}
:invoices {:type '(list :invoice_check)
:resolve :get-checks-invoices}
}}
:transaction {:fields {:id {:type 'Int} :transaction {:fields {:id {:type 'Int}
:amount {:type 'String} :amount {:type 'String}
@@ -98,6 +106,7 @@
:invoice_check :invoice_check
{:fields {:id {:type 'Int} {:fields {:id {:type 'Int}
:amount {:type 'String} :amount {:type 'String}
:invoice_id {:type 'Int}
:check_id {:type 'Int} :check_id {:type 'Int}
:check {:type :check :check {:type :check
:resolve :get-check-by-id}}} :resolve :get-check-by-id}}}
@@ -183,6 +192,14 @@
:resolve :get-invoice-page} :resolve :get-invoice-page}
:all_invoices {:type '(list :invoice)
:args {:company_id {:type 'Int}}
:resolve :get-all-invoices}
:all_checks {:type '(list :check)
:args {:company_id {:type 'Int}}
:resolve :get-all-checks}
:transaction_page {:type '(list :transaction_page) :transaction_page {:type '(list :transaction_page)
:args {:company_id {:type 'Int} :args {:company_id {:type 'Int}
:start {:type 'Int} :start {:type 'Int}
@@ -318,6 +335,35 @@
:start (:start args 0) :start (:start args 0)
:end (+ (:start args 0) (count invoices))}] extra-context))) :end (+ (:start args 0) (count invoices))}] extra-context)))
(defn get-all-invoices [context args value]
(let [extra-context
(cond-> {}
(executor/selects-field? context :invoice/vendor) (assoc :vendor-cache (by :id (vendors/get-all)))
(executor/selects-field? context :invoice/company) (assoc :company-cache (by :id (companies/get-all))))
invoices (map
->graphql
(invoices/get-graphql (assoc (<-graphql args)
:limit Integer/MAX_VALUE)))]
(resolve/with-context
invoices extra-context)))
(defn get-all-checks [context args value]
(let [extra-context
(cond-> {}
(executor/selects-field? context :invoice/vendor) (assoc :vendor-cache (by :id (vendors/get-all)))
(or (executor/selects-field? context :check/company)
(executor/selects-field? context :check/bank_account)) (assoc :company-cache (by :id (companies/get-all))))
checks (map
->graphql
(checks/get-graphql (assoc (<-graphql args)
:limit Integer/MAX_VALUE)))]
(resolve/with-context
checks extra-context)))
(defn get-reminder-page [context args value] (defn get-reminder-page [context args value]
(let [extra-context (let [extra-context
(cond-> {} (cond-> {}
@@ -348,12 +394,23 @@
(->graphql (->graphql
(invoices-checks/get-for-invoice-id (:id value)))) (invoices-checks/get-for-invoice-id (:id value))))
(defn get-checks-invoices [context args value]
(->graphql
(invoices-checks/get-for-check-id (:id value))))
(defn get-company-for-invoice [context args value] (defn get-company-for-invoice [context args value]
(->graphql (->graphql
(if-let [company-cache (:company-cache context)] (if-let [company-cache (:company-cache context)]
(company-cache (:company_id value)) (company-cache (:company_id value))
(companies/get-by-id (:company_id value))))) (companies/get-by-id (:company_id value)))))
(defn bank-account-for-check [context args value]
(->graphql
(let [company (if-let [company-cache (:company-cache context)]
(company-cache (:company_id value))
(companies/get-by-id (:company_id value)))]
(first (filter #(= (:id %) (:bank_account_id value)) (:bank-accounts company))) )))
(defn get-user-companies [context args value] (defn get-user-companies [context args value]
(->graphql (->graphql
(if-let [company-cache (:company-cache context)] (if-let [company-cache (:company-cache context)]
@@ -401,6 +458,10 @@
(def schema (def schema
(-> integreat-schema (-> integreat-schema
(attach-resolvers {:get-invoice-page get-invoice-page (attach-resolvers {:get-invoice-page get-invoice-page
:get-all-invoices get-all-invoices
:get-all-checks get-all-checks
:bank-account-for-check bank-account-for-check
:get-check-page gq-checks/get-check-page :get-check-page gq-checks/get-check-page
:get-transaction-page gq-transactions/get-transaction-page :get-transaction-page gq-transactions/get-transaction-page
:get-reminder-page get-reminder-page :get-reminder-page get-reminder-page
@@ -411,6 +472,7 @@
:get-check-for-transaction gq-transactions/get-check-for-transaction :get-check-for-transaction gq-transactions/get-check-for-transaction
:get-company-for-invoice get-company-for-invoice :get-company-for-invoice get-company-for-invoice
:get-invoices-checks get-invoices-checks :get-invoices-checks get-invoices-checks
:get-checks-invoices get-checks-invoices
:get-check-by-id get-check-by-id :get-check-by-id get-check-by-id
:get-invoices-expense-accounts gq-invoices/get-invoices-expense-accounts :get-invoices-expense-accounts gq-invoices/get-invoices-expense-accounts
:get-company get-company :get-company get-company
@@ -452,5 +514,5 @@
([id q] ([id q]
(query id q nil )) (query id q nil ))
([id q v] ([id q v]
(println id q v) (println "executing graphql query" id q v)
(simplify (execute schema q v {:identity id})))) (simplify (execute schema q v {:identity id}))))

View File

@@ -8,27 +8,42 @@
[auto-ap.db.utils :refer [query]] [auto-ap.db.utils :refer [query]]
[auto-ap.utils :refer [by]] [auto-ap.utils :refer [by]]
[auto-ap.parse :as parse] [auto-ap.parse :as parse]
[auto-ap.graphql :as graphql]
[auto-ap.graphql.utils :refer [->graphql]]
[auto-ap.routes.utils :refer [wrap-secure]] [auto-ap.routes.utils :refer [wrap-secure]]
[clj-time.coerce :refer [to-date]] [clj-time.coerce :refer [to-date]]
[auto-ap.db.invoices-expense-accounts :as expense-accounts] [auto-ap.db.invoices-expense-accounts :as expense-accounts]
[ring.middleware.json :refer [wrap-json-response]] [ring.middleware.json :refer [wrap-json-response]]
[compojure.core :refer [GET POST context defroutes wrap-routes]] [compojure.core :refer [GET POST context defroutes wrap-routes]]
[clojure.string :as str])) [clojure.string :as str]
[venia.core :as venia]))
(defroutes routes (defroutes routes
(wrap-routes (wrap-routes
(wrap-routes (wrap-routes
(context "/" [] (context "/" []
(GET "/invoices/export" {:keys [query-params]} (GET "/invoices/export" {:keys [query-params identity] :as request}
(let [invoices (invoices/get-graphql {:company (query-params "company")})] (let [query [[:all_invoices
(map (fn [i] {:company-id (query-params "company")}
(update i :date to-date)) [:id :total :outstanding-balance :invoice-number :date
invoices))) [:checks [:amount [:check [:check-number]]]]
[:vendor [:name :id]]
[:expense_accounts [:amount :id :expense_account_id :location
[:expense_account [:id :name [:parent [:id :name]]]]]]
[:company [:name :id :locations]]]]]
invoices (graphql/query identity (venia/graphql-query {:venia/queries (->graphql query)}))]
(list (:all-invoices (:data invoices)))))
(GET "/checks/export" {:keys [query-params]} (GET "/checks/export" {:keys [query-params]}
(let [checks (checks/get-graphql {:company (query-params "company")})] (let [query [[:all_checks
(map (fn [i] {:company-id (query-params "company")}
(update i :date to-date)) [:id :check-number :amount :memo :date
checks))) [:invoices [:invoice-id :amount]]
[:bank-account [:number :bank-name :bank-code]]
[:vendor [:name :id :primary-contact :primary-email :primary-phone :default-expense-account]]
[:company [:id :name]]
]]]
checks (graphql/query identity (venia/graphql-query {:venia/queries (->graphql query)}))]
(list (:all-checks (:data checks)))))
(GET "/companies/export" {:keys [query-params]} (GET "/companies/export" {:keys [query-params]}
(companies/get-all)) (companies/get-all))