vendor querying step 1.
This commit is contained in:
@@ -1,6 +1,14 @@
|
||||
(ns auto-ap.datomic.migrate.vendors
|
||||
(:require [datomic.api :as d]
|
||||
[auto-ap.datomic :refer [uri]]))
|
||||
(:require [datomic.api :as d]))
|
||||
|
||||
(defn add-vendor-search-terms [conn]
|
||||
[(->> (d/q '[:find ?i ?n
|
||||
:in $
|
||||
:where [?i :vendor/name ?n]]
|
||||
(d/db conn))
|
||||
(map (fn [[i n]]
|
||||
{:db/id i
|
||||
:vendor/search-terms n})))])
|
||||
|
||||
(def norms-map {:add-1099-stuff {:txes [[{:db/ident :vendor/legal-entity-first-name
|
||||
:db/doc "The first name for the legal entity"
|
||||
@@ -56,7 +64,15 @@
|
||||
:db/valueType :db.type/long
|
||||
:db/cardinality :db.cardinality/one
|
||||
:db/noHistory true}]
|
||||
]}})
|
||||
]}
|
||||
::make-fulltext-search {:txes [[{:db/ident :vendor/search-terms
|
||||
:db/valueType :db.type/string
|
||||
:db/cardinality :db.cardinality/many
|
||||
:db/doc "a name search for vendors"
|
||||
:db/fulltext true}]]
|
||||
:requires [:auto-ap/base-schema]}
|
||||
::add-vendor-search-terms {:txes-fn `add-vendor-search-terms
|
||||
:requires [::make-fulltext-search]}})
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -85,6 +85,18 @@
|
||||
(map #(trim-usage % (limited-clients (:id args))))
|
||||
#_(map #(assoc % :usage (get usages (:db/id %))))))
|
||||
|
||||
(defn get-graphql-by-id [args id]
|
||||
(->> (cond-> {:query {:find [(list 'pull '?e default-read)]
|
||||
:in ['$ '?e]
|
||||
:where ['[?e :vendor/name]]}
|
||||
:args [(d/db (d/connect uri)) id]})
|
||||
(d/query)
|
||||
(map first)
|
||||
(map #(cleanse (:id args) %))
|
||||
(map <-datomic)
|
||||
(map #(trim-usage % (limited-clients (:id args))))
|
||||
first))
|
||||
|
||||
(defn get-by-id [id]
|
||||
|
||||
(->> (d/q '[:find (pull ?e [*
|
||||
|
||||
@@ -98,6 +98,10 @@
|
||||
:message
|
||||
{:fields {:message {:type 'String}}}
|
||||
|
||||
:search_result
|
||||
{:fields {:name {:type 'String}
|
||||
:id {:type :id}}}
|
||||
|
||||
:yodlee_provider_account
|
||||
{:fields {:id {:type 'Int}
|
||||
:client {:type :client}
|
||||
@@ -347,6 +351,10 @@
|
||||
:args {:account_set {:type 'String}}
|
||||
:resolve :get-accounts}
|
||||
|
||||
:search_vendor {:type '(list :search_result)
|
||||
:args {:query {:type 'String}}
|
||||
:resolve :search-vendor}
|
||||
|
||||
|
||||
|
||||
:all_sales_orders {:type '(list :sales_order)
|
||||
@@ -393,7 +401,10 @@
|
||||
:vendor {:type '(list :vendor)
|
||||
:resolve :get-vendor}
|
||||
:user {:type '(list :user)
|
||||
:resolve :get-user}}
|
||||
:resolve :get-user}
|
||||
:vendor_by_id {:type :vendor
|
||||
:args {:id {:type :id}}
|
||||
:resolve :vendor-by-id}}
|
||||
|
||||
:input-objects
|
||||
{
|
||||
@@ -777,6 +788,7 @@
|
||||
:get-cash-flow get-cash-flow
|
||||
:get-yodlee-merchants ym/get-yodlee-merchants
|
||||
:get-intuit-bank-accounts gq-intuit-bank-accounts/get-intuit-bank-accounts
|
||||
:vendor-by-id gq-vendors/get-by-id
|
||||
:get-user get-user
|
||||
:mutation/delete-transaction-rule gq-transaction-rules/delete-transaction-rule
|
||||
:mutation/edit-user gq-users/edit-user
|
||||
@@ -787,7 +799,8 @@
|
||||
:mutation/upsert-account gq-accounts/upsert-account
|
||||
:mutation/merge-vendors gq-vendors/merge-vendors
|
||||
:mutation/request-import gq-requests/request-import
|
||||
:get-vendor gq-vendors/get-graphql})
|
||||
:get-vendor gq-vendors/get-graphql
|
||||
:search-vendor gq-vendors/search})
|
||||
gq-checks/attach
|
||||
gq-ledger/attach
|
||||
gq-reports/attach
|
||||
|
||||
@@ -117,3 +117,21 @@
|
||||
(defn get-graphql [context args value]
|
||||
(->graphql
|
||||
(d-vendors/get-graphql (assoc args :id (:id context)))))
|
||||
|
||||
(defn get-by-id [context args value]
|
||||
(->graphql
|
||||
(d-vendors/get-graphql-by-id (assoc args :id (:id context))
|
||||
(:id args))))
|
||||
|
||||
(defn search [context args value]
|
||||
(->> (d/q '[:find ?n ?i ?s
|
||||
:in $ ?q
|
||||
:where [(fulltext $ :vendor/search-terms ?q) [[?i ?n _ ?s]]]
|
||||
(not [?i :vendor/hidden true])]
|
||||
(d/db conn)
|
||||
(:query args))
|
||||
(sort-by last)
|
||||
(map (fn [[n i]]
|
||||
{:name n
|
||||
:id i}
|
||||
))))
|
||||
|
||||
Reference in New Issue
Block a user