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