fixed common errors.

This commit is contained in:
Bryce Covert
2022-12-31 09:37:08 -08:00
parent 98eeb223f4
commit 0f062e0236
4 changed files with 118 additions and 105 deletions

View File

@@ -79,6 +79,7 @@
second second
(not-empty ) (not-empty )
Integer/parseInt)] Integer/parseInt)]
(if query
(if num (if num
(->> (d/q '[:find ?n (pull ?i [:db/id :account/numeric-code :account/location]) (->> (d/q '[:find ?n (pull ?i [:db/id :account/numeric-code :account/location])
:in $ ?numeric-code :in $ ?numeric-code
@@ -114,5 +115,6 @@
(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)}))))
[])))

View File

@@ -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 "*"))
query (as-> exacts e
(filter #(not (str/blank? %)) e)
(mapv #(str "+" %) e) (mapv #(str "+" %) e)
(conj e (str partial "*")) (conj e partial)
(str/join " " e))))) (str/join " " e))]
(not-empty query))))

View File

@@ -182,8 +182,8 @@
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]]]]
@@ -200,4 +200,5 @@
(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}))))
[]))

View File

@@ -200,7 +200,11 @@
::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]
: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 {:graphql
{:token user {:token user
:owns-state {:single ::form} :owns-state {:single ::form}
@@ -225,13 +229,16 @@
:type type} :type type}
[:pdf-url [:invoices invoice-read]]]}]} [:pdf-url [:invoices invoice-read]]]}]}
:on-success [::added-and-printed] :on-success [::added-and-printed]
:on-error [::forms/save-error ::form]}})) :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))
{:dispatch-n [[::status/error ::form [{:message "Please fix the errors and try again."}]]
[::forms/attempted-submit ::form]]}
{:graphql {:graphql
{:token user {:token user
:owns-state {:single ::form} :owns-state {:single ::form}
@@ -247,7 +254,7 @@
(if (:id data) (if (:id data)
:edit :edit
:create)]) :create)])
:on-error [::forms/save-error ::form]}})) :on-error [::forms/save-error ::form]}})))
(re-frame/reg-event-fx (re-frame/reg-event-fx
::save-requested ::save-requested