fixed common errors.
This commit is contained in:
@@ -79,40 +79,42 @@
|
||||
second
|
||||
(not-empty )
|
||||
Integer/parseInt)]
|
||||
(if num
|
||||
(->> (d/q '[:find ?n (pull ?i [:db/id :account/numeric-code :account/location])
|
||||
:in $ ?numeric-code
|
||||
:where [?i :account/numeric-code ?numeric-code]
|
||||
[?i :account/name ?n]]
|
||||
(d/db conn)
|
||||
num)
|
||||
(map (fn [[n a]]
|
||||
{:name (str (:account/numeric-code a) " - " n)
|
||||
:id (:db/id a)
|
||||
:location (:account/location a)})))
|
||||
(if query
|
||||
(if num
|
||||
(->> (d/q '[:find ?n (pull ?i [:db/id :account/numeric-code :account/location])
|
||||
:in $ ?numeric-code
|
||||
:where [?i :account/numeric-code ?numeric-code]
|
||||
[?i :account/name ?n]]
|
||||
(d/db conn)
|
||||
num)
|
||||
(map (fn [[n a]]
|
||||
{:name (str (:account/numeric-code a) " - " n)
|
||||
:id (:db/id a)
|
||||
:location (:account/location a)})))
|
||||
|
||||
(->> (d/q '[:find ?n (pull ?i [:db/id :account/numeric-code :account/location]) ?s
|
||||
:in $ ?q
|
||||
:where [(fulltext $ :account/search-terms ?q) [[?i ?n _ ?s]]]
|
||||
[?i :account/numeric-code ?numeric-code]
|
||||
(or [?i :account/applicability :account-applicability/global]
|
||||
[?i :account/applicability :account-applicability/optional])]
|
||||
(d/db conn)
|
||||
query)
|
||||
(concat (when client
|
||||
(d/q '[:find ?n (pull ?a [:db/id :account/numeric-code :account/location]) ?s
|
||||
:in $ ?c ?q
|
||||
:where
|
||||
[?i :account-client-override/client ?c]
|
||||
[(fulltext $ :account-client-override/search-terms ?q) [[?i ?n _ ?s]]]
|
||||
[?a :account/client-overrides ?i]
|
||||
[?a :account/numeric-code ?numeric-code]]
|
||||
(d/db conn)
|
||||
client
|
||||
query)))
|
||||
(sort-by (comp - last))
|
||||
(map (fn [[n a]]
|
||||
{:name (str (:account/numeric-code a) " - " n)
|
||||
:id (:db/id a)
|
||||
:location (:account/location a)}))))))
|
||||
(->> (d/q '[:find ?n (pull ?i [:db/id :account/numeric-code :account/location]) ?s
|
||||
:in $ ?q
|
||||
:where [(fulltext $ :account/search-terms ?q) [[?i ?n _ ?s]]]
|
||||
[?i :account/numeric-code ?numeric-code]
|
||||
(or [?i :account/applicability :account-applicability/global]
|
||||
[?i :account/applicability :account-applicability/optional])]
|
||||
(d/db conn)
|
||||
query)
|
||||
(concat (when client
|
||||
(d/q '[:find ?n (pull ?a [:db/id :account/numeric-code :account/location]) ?s
|
||||
:in $ ?c ?q
|
||||
:where
|
||||
[?i :account-client-override/client ?c]
|
||||
[(fulltext $ :account-client-override/search-terms ?q) [[?i ?n _ ?s]]]
|
||||
[?a :account/client-overrides ?i]
|
||||
[?a :account/numeric-code ?numeric-code]]
|
||||
(d/db conn)
|
||||
client
|
||||
query)))
|
||||
(sort-by (comp - last))
|
||||
(map (fn [[n a]]
|
||||
{:name (str (:account/numeric-code a) " - " n)
|
||||
:id (:db/id a)
|
||||
:location (:account/location a)}))))
|
||||
[])))
|
||||
|
||||
|
||||
@@ -128,12 +128,15 @@
|
||||
(if (str/includes? q "&")
|
||||
(str "\"" q "\"~0.8")
|
||||
(let [parts (-> q
|
||||
(str/replace #"[\[\]\+\*\-]" "")
|
||||
(str/split #"\s+"))
|
||||
(str/replace #"[\[\]\+\*\-\?]" "")
|
||||
(str/split #"\s+"))
|
||||
exacts (butlast parts)
|
||||
partial (last parts)]
|
||||
(as-> exacts e
|
||||
|
||||
(mapv #(str "+" %) e)
|
||||
(conj e (str partial "*"))
|
||||
(str/join " " e)))))
|
||||
partial (some-> (last parts)
|
||||
not-empty
|
||||
(str "*"))
|
||||
query (as-> exacts e
|
||||
(filter #(not (str/blank? %)) e)
|
||||
(mapv #(str "+" %) e)
|
||||
(conj e partial)
|
||||
(str/join " " e))]
|
||||
(not-empty query))))
|
||||
|
||||
@@ -182,22 +182,23 @@
|
||||
matches))
|
||||
|
||||
(defn search [context args _]
|
||||
(let [search-query (cleanse-query (:query args))
|
||||
data (if (is-admin? (:id context))
|
||||
(d/q '[:find ?n ?i ?s
|
||||
:in $ ?q
|
||||
:where [(fulltext $ :vendor/search-terms ?q) [[?i ?n _ ?s]]]]
|
||||
(d/db conn)
|
||||
search-query)
|
||||
(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)
|
||||
search-query))]
|
||||
(->> data
|
||||
(sort-by (comp - last))
|
||||
(partial-match-first (:query args))
|
||||
(map (fn [[n i]]
|
||||
{:name n
|
||||
:id i})))))
|
||||
(if-let [search-query (cleanse-query (:query args))]
|
||||
(let [data (if (is-admin? (:id context))
|
||||
(d/q '[:find ?n ?i ?s
|
||||
:in $ ?q
|
||||
:where [(fulltext $ :vendor/search-terms ?q) [[?i ?n _ ?s]]]]
|
||||
(d/db conn)
|
||||
search-query)
|
||||
(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)
|
||||
search-query))]
|
||||
(->> data
|
||||
(sort-by (comp - last))
|
||||
(partial-match-first (:query args))
|
||||
(map (fn [[n i]]
|
||||
{:name n
|
||||
:id i}))))
|
||||
[]))
|
||||
|
||||
@@ -200,54 +200,61 @@
|
||||
::add-and-print
|
||||
[with-user (forms/in-form ::form)]
|
||||
(fn [{:keys [user]
|
||||
{{:keys [invoice-number date location total expense-accounts scheduled-payment vendor client]} :data} :db} [_ bank-account-id type]]
|
||||
{:graphql
|
||||
{:token user
|
||||
:owns-state {:single ::form}
|
||||
:query-obj {:venia/operation {:operation/type :mutation
|
||||
:operation/name "AddAndPrintInvoice"}
|
||||
:venia/queries [{:query/data [:add-and-print-invoice
|
||||
{:invoice {:date date
|
||||
:vendor-id (:id vendor)
|
||||
:client-id (:id client)
|
||||
:scheduled-payment scheduled-payment
|
||||
:invoice-number invoice-number
|
||||
:location location
|
||||
:total total
|
||||
:expense-accounts (map (fn [ea]
|
||||
{:id (when-not (str/starts-with? (:id ea) "new-")
|
||||
(:id ea))
|
||||
:account_id (:id (:account ea))
|
||||
:location (:location ea)
|
||||
:amount (:amount ea)})
|
||||
expense-accounts)}
|
||||
:bank-account-id bank-account-id
|
||||
:type type}
|
||||
[:pdf-url [:invoices invoice-read]]]}]}
|
||||
:on-success [::added-and-printed]
|
||||
:on-error [::forms/save-error ::form]}}))
|
||||
{{:keys [invoice-number date location total expense-accounts scheduled-payment vendor client]
|
||||
:as data} :data} :db} [_ bank-account-id type]]
|
||||
(if (not (m/validate schema data))
|
||||
{:dispatch-n [[::status/error ::form [{:message "Please fix the errors and try again."}]]
|
||||
[::forms/attempted-submit ::form]]}
|
||||
{:graphql
|
||||
{:token user
|
||||
:owns-state {:single ::form}
|
||||
:query-obj {:venia/operation {:operation/type :mutation
|
||||
:operation/name "AddAndPrintInvoice"}
|
||||
:venia/queries [{:query/data [:add-and-print-invoice
|
||||
{:invoice {:date date
|
||||
:vendor-id (:id vendor)
|
||||
:client-id (:id client)
|
||||
:scheduled-payment scheduled-payment
|
||||
:invoice-number invoice-number
|
||||
:location location
|
||||
:total total
|
||||
:expense-accounts (map (fn [ea]
|
||||
{:id (when-not (str/starts-with? (:id ea) "new-")
|
||||
(:id ea))
|
||||
:account_id (:id (:account ea))
|
||||
:location (:location ea)
|
||||
:amount (:amount ea)})
|
||||
expense-accounts)}
|
||||
:bank-account-id bank-account-id
|
||||
:type type}
|
||||
[:pdf-url [:invoices invoice-read]]]}]}
|
||||
:on-success [::added-and-printed]
|
||||
:on-error [::forms/save-error ::form]}})
|
||||
))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::saving
|
||||
[with-user (forms/in-form ::form) (re-frame/inject-cofx ::inject/sub [::edit-query]) (re-frame/inject-cofx ::inject/sub [::create-query])]
|
||||
(fn [{:keys [user] {:keys [data]} :db ::keys [edit-query create-query]} _]
|
||||
(println "DATA IS" data)
|
||||
{:graphql
|
||||
{:token user
|
||||
:owns-state {:single ::form}
|
||||
:query-obj (if (:id data)
|
||||
edit-query
|
||||
create-query)
|
||||
:on-success (fn [result]
|
||||
[::updated
|
||||
(assoc (if (:id data)
|
||||
(:edit-invoice result)
|
||||
(:add-invoice result))
|
||||
:class "live-added")
|
||||
(if (:id data)
|
||||
:edit
|
||||
:create)])
|
||||
:on-error [::forms/save-error ::form]}}))
|
||||
(if (not (m/validate schema data))
|
||||
{:dispatch-n [[::status/error ::form [{:message "Please fix the errors and try again."}]]
|
||||
[::forms/attempted-submit ::form]]}
|
||||
{:graphql
|
||||
{:token user
|
||||
:owns-state {:single ::form}
|
||||
:query-obj (if (:id data)
|
||||
edit-query
|
||||
create-query)
|
||||
:on-success (fn [result]
|
||||
[::updated
|
||||
(assoc (if (:id data)
|
||||
(:edit-invoice result)
|
||||
(:add-invoice result))
|
||||
:class "live-added")
|
||||
(if (:id data)
|
||||
:edit
|
||||
:create)])
|
||||
:on-error [::forms/save-error ::form]}})))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::save-requested
|
||||
|
||||
Reference in New Issue
Block a user