making cloud runnable again.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
(ns auto-ap.ezcater.core
|
||||
(:require
|
||||
[auto-ap.datomic :refer [conn]]
|
||||
[datomic.api :as d]
|
||||
[auto-ap.datomic :refer [conn random-tempid]]
|
||||
[datomic.client.api :as dc]
|
||||
[clj-http.client :as client]
|
||||
[venia.core :as v]
|
||||
[clojure.string :as str]
|
||||
@@ -35,40 +35,40 @@
|
||||
:subscriptions))
|
||||
|
||||
(defn get-integrations []
|
||||
(map first (d/q '[:find (pull ?i [:ezcater-integration/api-key
|
||||
(map first (dc/q '[:find (pull ?i [:ezcater-integration/api-key
|
||||
:ezcater-integration/subscriber-uuid
|
||||
:db/id
|
||||
:ezcater-integration/integration-status [:db/id]])
|
||||
:in $
|
||||
:where [?i :ezcater-integration/api-key]]
|
||||
(d/db conn))))
|
||||
(dc/db conn))))
|
||||
|
||||
(defn mark-integration-status [integration integration-status]
|
||||
@(d/transact conn
|
||||
[{:db/id (:db/id integration)
|
||||
:ezcater-integration/integration-status (assoc integration-status
|
||||
:db/id (or (-> integration :ezcater-integration/integration-status :db/id)
|
||||
#db/id [:db.part/user]))}]))
|
||||
(dc/transact conn
|
||||
{:tx-data [{:db/id (:db/id integration)
|
||||
:ezcater-integration/integration-status (assoc integration-status
|
||||
:db/id (or (-> integration :ezcater-integration/integration-status :db/id)
|
||||
(random-tempid)))}]}))
|
||||
|
||||
(defn upsert-caterers
|
||||
([integration]
|
||||
@(d/transact
|
||||
(dc/transact
|
||||
conn
|
||||
(for [caterer (get-caterers integration)]
|
||||
{:db/id (:db/id integration)
|
||||
:ezcater-integration/caterers [{:ezcater-caterer/name (str (:name caterer) " (" (:street (:address caterer)) ")")
|
||||
:ezcater-caterer/search-terms (str (:name caterer) " " (:street (:address caterer)))
|
||||
:ezcater-caterer/uuid (:uuid caterer)}]}))))
|
||||
{:tx-data (for [caterer (get-caterers integration)]
|
||||
{:db/id (:db/id integration)
|
||||
:ezcater-integration/caterers [{:ezcater-caterer/name (str (:name caterer) " (" (:street (:address caterer)) ")")
|
||||
:ezcater-caterer/search-terms (str (:name caterer) " " (:street (:address caterer)))
|
||||
:ezcater-caterer/uuid (:uuid caterer)}]})})))
|
||||
|
||||
(defn upsert-used-subscriptions
|
||||
([integration]
|
||||
(let [extant (get-subscriptions integration)
|
||||
to-ensure (set (map first (d/q '[:find ?cu
|
||||
to-ensure (set (map first (dc/q '[:find ?cu
|
||||
:in $
|
||||
:where [_ :client/ezcater-locations ?el]
|
||||
[?el :ezcater-location/caterer ?c]
|
||||
[?c :ezcater-caterer/uuid ?cu]]
|
||||
(d/db conn))))
|
||||
(dc/db conn))))
|
||||
to-create (set/difference
|
||||
to-ensure
|
||||
(set (map :parentId extant)))]
|
||||
@@ -114,7 +114,7 @@
|
||||
:integration-status/message (.getMessage e)}))))))
|
||||
|
||||
(defn get-caterer [caterer-uuid]
|
||||
(d/pull (d/db conn)
|
||||
(dc/pull (dc/db conn)
|
||||
'[:ezcater-caterer/name
|
||||
{:ezcater-integration/_caterers [:ezcater-integration/api-key]}
|
||||
{:ezcater-location/_caterer [:ezcater-location/location
|
||||
@@ -270,12 +270,12 @@
|
||||
(alog/info
|
||||
::try-import-order
|
||||
:json json)
|
||||
@(d/transact conn (filter identity
|
||||
[(some-> json
|
||||
(lookup-order)
|
||||
(order->sales-order)
|
||||
(update :sales-order/date coerce/to-date)
|
||||
(update-in [:sales-order/charges 0 :charge/date] coerce/to-date))])))
|
||||
(dc/transact conn {:tx-data (filter identity
|
||||
[(some-> json
|
||||
(lookup-order)
|
||||
(order->sales-order)
|
||||
(update :sales-order/date coerce/to-date)
|
||||
(update-in [:sales-order/charges 0 :charge/date] coerce/to-date))])}))
|
||||
|
||||
(defn upsert-recent []
|
||||
(upsert-ezcater)
|
||||
@@ -346,6 +346,6 @@
|
||||
updated-order))]
|
||||
(alog/info :found-orders-to-update
|
||||
:orders orders-to-update)
|
||||
@(d/transact conn orders-to-update)))
|
||||
@(dc/transact conn {:tx-data orders-to-update})))
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user