Skip to content

Commit

Permalink
Merge pull request #405 from district0x/various-fixes-7
Browse files Browse the repository at this point in the history
More fixes
  • Loading branch information
madis authored May 11, 2024
2 parents e55e0ad + e0092c5 commit ed75ff2
Show file tree
Hide file tree
Showing 5 changed files with 138 additions and 109 deletions.
126 changes: 64 additions & 62 deletions server/src/ethlance/server/graphql/resolvers.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -271,68 +271,69 @@


(defn arbiter-search-resolver
[_ {:keys [:limit :offset
[_first {:keys [:limit :offset
:user/id
:search-params
:order-by :order-direction]
:as args} _]
(db/with-async-resolver-conn conn
(log/debug "arbiter-search-resolver" args)
(let [search-params (js-obj->clj-map search-params)
categories-and (when (:category search-params) [(:category search-params)])
categories-or nil ; Not used, switch form ...-and if want this behaviour
skills-and (or (js->clj (:skills search-params)) [])
skills-or nil ; Not used, switch form ...-and if want this behaviour
min-rating (:feedback-min-rating search-params)
max-rating (:feedback-max-rating search-params)
min-fee (:min-fee search-params)
max-fee (:max-fee search-params)
min-num-feedbacks (:min-num-feedbacks search-params)
country (:country search-params)
user-name (:name search-params)

query (cond-> (merge arbiter-query {:modifiers [:distinct]})
min-rating (sql-helpers/merge-where [:<= min-rating :Arbiter.arbiter/rating])
max-rating (sql-helpers/merge-where [:>= max-rating :Arbiter.arbiter/rating])
(and (nil? min-rating)
(not (nil? max-rating))) (sql-helpers/merge-where :or [:= nil :Arbiter.arbiter/rating])
id (sql-helpers/merge-where [:ilike :Arbiter.user/id id])

country (sql-helpers/merge-where [:= country :Users.user/country])

categories-or (sql-helpers/merge-left-join :ArbiterCategory
[:= :ArbiterCategory.user/id :Arbiter.user/id])

categories-or (sql-helpers/merge-where [:in :ArbiterCategory.category/id categories-or])

categories-and (match-all {:join-table :ArbiterCategory
:on-column :user/id
:column :category/id
:all-values categories-and})

skills-or (sql-helpers/merge-left-join :ArbiterSkill
[:= :ArbiterSkill.user/id :Arbiter.user/id])

skills-or (sql-helpers/merge-where [:in :ArbiterSkill.skill/id skills-or])
min-fee (sql-helpers/merge-where [:>= :Arbiter.arbiter/fee min-fee])
max-fee (sql-helpers/merge-where [:<= :Arbiter.arbiter/fee max-fee])
min-num-feedbacks (sql-helpers/merge-where
[:<= min-num-feedbacks
{:select [(sql/call :count :*)]
:from [:JobStoryFeedbackMessage]
:where [:= :JobStoryFeedbackMessage.user/id :Arbiter.user/id]}])

(not (empty? skills-and)) (match-all {:join-table :ArbiterSkill
:on-column :user/id
:column :skill/id
:all-values skills-and})

user-name (sql-helpers/merge-where [:ilike :Users.user/name (sql/raw (str "'%" user-name "%'"))])
order-by (sql-helpers/merge-order-by [[(get {:date-registered :user/date-registered
:date-updated :user/date-updated}
(graphql-utils/gql-name->kw order-by))
(or (keyword order-direction) :asc)]]))]
(<? (paged-query conn query limit offset)))))
:as args} _last]
(db/with-async-resolver-conn
conn
(log/debug "arbiter-search-resolver" args)
(let [search-params (js-obj->clj-map search-params)
categories-and (when (:category search-params) [(:category search-params)])
categories-or nil ; Not used, switch form ...-and if want this behaviour
skills-and (or (js->clj (:skills search-params)) [])
skills-or nil ; Not used, switch form ...-and if want this behaviour
min-rating (:feedback-min-rating search-params)
max-rating (:feedback-max-rating search-params)
min-fee (:min-fee search-params)
max-fee (:max-fee search-params)
min-num-feedbacks (:min-num-feedbacks search-params)
country (:country search-params)
user-name (:name search-params)

query (cond-> (merge arbiter-query {:modifiers [:distinct]})
min-rating (sql-helpers/merge-where [:<= min-rating :Arbiter.arbiter/rating])
max-rating (sql-helpers/merge-where [:>= max-rating :Arbiter.arbiter/rating])
(and (nil? min-rating)
(not (nil? max-rating))) (sql-helpers/merge-where :or [:= nil :Arbiter.arbiter/rating])
id (sql-helpers/merge-where [:ilike :Arbiter.user/id id])

country (sql-helpers/merge-where [:= country :Users.user/country])

categories-or (sql-helpers/merge-left-join :ArbiterCategory
[:= :ArbiterCategory.user/id :Arbiter.user/id])

categories-or (sql-helpers/merge-where [:in :ArbiterCategory.category/id categories-or])

categories-and (match-all {:join-table :ArbiterCategory
:on-column :user/id
:column :category/id
:all-values categories-and})

skills-or (sql-helpers/merge-left-join :ArbiterSkill
[:= :ArbiterSkill.user/id :Arbiter.user/id])

skills-or (sql-helpers/merge-where [:in :ArbiterSkill.skill/id skills-or])
min-fee (sql-helpers/merge-where [:>= :Arbiter.arbiter/fee min-fee])
max-fee (sql-helpers/merge-where [:<= :Arbiter.arbiter/fee max-fee])
min-num-feedbacks (sql-helpers/merge-where
[:<= min-num-feedbacks
{:select [(sql/call :count :*)]
:from [:JobStoryFeedbackMessage]
:where [:= :JobStoryFeedbackMessage.user/id :Arbiter.user/id]}])

(not (empty? skills-and)) (match-all {:join-table :ArbiterSkill
:on-column :user/id
:column :skill/id
:all-values skills-and})

user-name (sql-helpers/merge-where [:ilike :Users.user/name (sql/raw (str "'%" user-name "%'"))])
order-by (sql-helpers/merge-order-by [[(get {:date-registered :user/date-registered
:date-updated :user/date-updated}
(graphql-utils/gql-name->kw order-by))
(or (keyword order-direction) :asc)]]))]
(<? (paged-query conn query limit offset)))))


(defn arbiter->feedback-resolver
Expand Down Expand Up @@ -482,14 +483,15 @@
(let [parent (graphql-utils/gql->clj raw-parent)
job-story-id (:job-story/id parent)
user-id (:user/id current-user)
_ (println ">>> job-story->direct-messages-resolver" {:job-story-id job-story-id :user-id user-id})
query {:select [:*]
:from [:DirectMessage]
:join [:Message [:= :Message.message/id :DirectMessage.message/id]]
:where [:and
[:= :DirectMessage.job-story/id job-story-id]
[:or
[:= :DirectMessage.direct-message/recipient user-id]
[:= :Message.message/creator user-id]]]}]
[:ilike :DirectMessage.direct-message/recipient user-id]
[:ilike :Message.message/creator user-id]]]}]
(<? (db/all conn query)))))


Expand Down Expand Up @@ -1147,7 +1149,7 @@
(assoc ,,, :arbiter (assoc arbiter :user/id user-id)))]
(log/debug "update-user-mutation")
(<? (ethlance-db/upsert-user! conn upsert-args))
(<? (db/get conn {:select [:*] :from [:Users] :where [:= :user/id user-id]})))))
(<? (db/get conn {:select [:*] :from [:Users] :where [:ilike :user/id user-id]})))))


(defn create-job-proposal-mutation
Expand Down
2 changes: 1 addition & 1 deletion ui/src/ethlance/ui/component/pagination.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
next-offset (if (>= next-offset total-count) offset next-offset)
first-offset 0
last-offset (* (- num-pages 1) limit)]
[:div.button-listing
[:div.button-listing (when (<= num-pages 2) {:style {:display :none}})
[c-circle-icon-button
{:name :ic-arrow-left2
:disabled? (= offset 0)
Expand Down
9 changes: 7 additions & 2 deletions ui/src/ethlance/ui/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
(:require
[akiroz.re-frame.storage]
[day8.re-frame.forward-events-fx]
[district.ui.web3.queries :as web3-queries]
[cljs-web3-next.utils :as w3n-utils]
[district.ui.web3-accounts.events :as accounts-events]
[district.ui.web3-account-balances.events :as account-balances-events]
[ethlance.ui.page.arbiters.events]
[ethlance.ui.page.candidates.events]
[ethlance.ui.page.home.events]
Expand All @@ -21,8 +24,10 @@

(re/reg-event-fx
::accounts-changed
(fn [_cofx [_event-name [new-active-account]]]
{:fx [[:dispatch [::accounts-events/set-active-account new-active-account]]]}))
(fn [{:keys [db]} [_event-name [new-active-account]]]
{:fx [[:dispatch [::accounts-events/set-active-account
(w3n-utils/address->checksum (web3-queries/web3 db) new-active-account)]]
[:dispatch [::account-balances-events/load-account-balances]]]}))

(re/reg-event-fx
::listen-account-changes
Expand Down
Loading

0 comments on commit ed75ff2

Please sign in to comment.