automated imports.
This commit is contained in:
49
src/clj/auto_ap/graphql/transactions.clj
Normal file
49
src/clj/auto_ap/graphql/transactions.clj
Normal file
@@ -0,0 +1,49 @@
|
||||
(ns auto-ap.graphql.transactions
|
||||
(:require [auto-ap.graphql.utils :refer [->graphql <-graphql]]
|
||||
|
||||
[com.walmartlabs.lacinia :refer [execute]]
|
||||
[com.walmartlabs.lacinia.executor :as executor]
|
||||
[com.walmartlabs.lacinia.resolve :as resolve]
|
||||
[auto-ap.db.transactions :as transactions]
|
||||
[auto-ap.db.vendors :as vendors]
|
||||
[auto-ap.db.checks :as checks]
|
||||
[auto-ap.utils :refer [by]]
|
||||
[auto-ap.db.companies :as companies]
|
||||
[auto-ap.time :refer [parse normal-date]]))
|
||||
|
||||
(defn get-vendor-for-transaction [context args value]
|
||||
(->graphql
|
||||
(if-let [vendor-cache (:vendor-cache context)]
|
||||
(vendor-cache (:vendor_id value))
|
||||
(vendors/get-by-id (:vendor_id value)))))
|
||||
|
||||
(defn get-check-for-transaction [context args value]
|
||||
(->graphql
|
||||
(checks/get-by-id (:check_id value))))
|
||||
|
||||
(defn get-company-for-transaction [context args value]
|
||||
(->graphql
|
||||
(if-let [company-cache (:company-cache context)]
|
||||
(company-cache (:company_id value))
|
||||
(companies/get-by-id (:company_id value)))))
|
||||
|
||||
(defn get-transaction-page [context args value]
|
||||
(let [extra-context
|
||||
(cond-> {}
|
||||
(executor/selects-field? context :invoice/vendor) (assoc :vendor-cache (by :id (vendors/get-all)))
|
||||
(executor/selects-field? context :invoice/company) (assoc :company-cache (by :id (companies/get-all))))
|
||||
|
||||
transactions (map
|
||||
->graphql
|
||||
(transactions/get-graphql (<-graphql args)))
|
||||
transactions-count (transactions/count-graphql (<-graphql args))]
|
||||
(resolve/with-context
|
||||
[{:transactions transactions
|
||||
:total transactions-count
|
||||
:count (count transactions)
|
||||
:start (:start args 0)
|
||||
:end (+ (:start args 0) (count transactions))}] extra-context)))
|
||||
|
||||
|
||||
|
||||
|
||||
35
src/clj/auto_ap/routes/events.clj
Normal file
35
src/clj/auto_ap/routes/events.clj
Normal file
@@ -0,0 +1,35 @@
|
||||
(ns auto-ap.routes.events
|
||||
(:require
|
||||
[auto-ap.db.reminders :as reminders]
|
||||
[auto-ap.db.vendors :as vendors]
|
||||
[auto-ap.routes.utils :refer [wrap-secure]]
|
||||
[auto-ap.yodlee.import :as yodlee-import]
|
||||
[config.core :refer [env]]
|
||||
[clj-http.client :as http]
|
||||
[clj-time.coerce :as c]
|
||||
[clj-time.core :as time]
|
||||
[clj-time.periodic :as p]
|
||||
[clj-time.predicates :as pred]
|
||||
[clojure.data.json :as json]
|
||||
[compojure.core :refer [GET PUT POST context defroutes
|
||||
wrap-routes]])
|
||||
(:import (org.joda.time DateTime)))
|
||||
|
||||
(defroutes routes
|
||||
(context "/events" []
|
||||
(POST "/yodlee-import" {:keys [query-params headers body] :as x}
|
||||
(let [notification-type (get headers "x-amz-sns-message-type")]
|
||||
(println "Received notification " notification-type)
|
||||
(if (= "SubscriptionConfirmation" notification-type)
|
||||
(do
|
||||
(println "Responding to confirmation" )
|
||||
(let [json (json/read-str (slurp body))]
|
||||
(println json)
|
||||
(http/get (get json "SubscribeURL"))))
|
||||
(do
|
||||
(println "importing from yodlee")
|
||||
(yodlee-import/do-import))))
|
||||
|
||||
{:status 200
|
||||
:body "{}"
|
||||
:headers {"Content-Type" "application/edn"}})))
|
||||
Reference in New Issue
Block a user