vendors.
This commit is contained in:
22
src/clj/auto_ap/db/vendors.clj
Normal file
22
src/clj/auto_ap/db/vendors.clj
Normal file
@@ -0,0 +1,22 @@
|
||||
(ns auto-ap.db.vendors
|
||||
(:require [clojure.java.jdbc :as j]
|
||||
[auto-ap.db.utils :refer [clj->db db->clj get-conn]]
|
||||
[clojure.edn :as edn]))
|
||||
|
||||
(defn merge-data [{:keys [data] :as x}]
|
||||
(merge x (edn/read-string data)))
|
||||
|
||||
(defn parse [x]
|
||||
(-> x
|
||||
(db->clj)
|
||||
merge-data
|
||||
))
|
||||
|
||||
|
||||
(defn get-all []
|
||||
(->> (j/query (get-conn) "SELECT * FROM vendors")
|
||||
(map parse)))
|
||||
|
||||
(defn upsert [id data]
|
||||
(j/update! (get-conn) :vendors (clj->db data) ["id = ?" (Integer/parseInt id)] )
|
||||
(merge-data (db->clj (first (j/query (get-conn) ["SELECT * FROM vendors WHERE id = ?" (Integer/parseInt id)])))))
|
||||
@@ -24,6 +24,7 @@
|
||||
[buddy.auth.backends.token :refer [jws-backend]]
|
||||
[buddy.auth.middleware :refer [wrap-authorization wrap-authentication]]
|
||||
[auto-ap.db.companies :as companies]
|
||||
[auto-ap.db.vendors :as vendors]
|
||||
[amazonica.core :refer [defcredential]]
|
||||
[amazonica.aws.simpleemail :as ses]))
|
||||
(defn best-match [companies company-identifier]
|
||||
@@ -88,6 +89,11 @@
|
||||
{:status 200
|
||||
:body (pr-str (companies/get-all))
|
||||
:headers {"Content-Type" "application/edn"}})
|
||||
|
||||
(GET "/api/vendors" []
|
||||
{:status 200
|
||||
:body (pr-str (vendors/get-all))
|
||||
:headers {"Content-Type" "application/edn"}})
|
||||
|
||||
(GET "/api/invoices" []
|
||||
{:status 200
|
||||
@@ -105,7 +111,7 @@
|
||||
:headers {"Content-Type" "application/edn"}})
|
||||
|
||||
(POST "/api/reminders/send" {:keys [query-params]}
|
||||
(doseq [{:keys [name email invoice-reminder-schedule]} (companies/get-all)]
|
||||
(doseq [{:keys [name email invoice-reminder-schedule]} (vendors/get-all)]
|
||||
(when (= "Weekly" invoice-reminder-schedule)
|
||||
(println "Sending email to" email)
|
||||
(ses/send-email :destination {:to-addresses [email]}
|
||||
@@ -122,6 +128,11 @@
|
||||
:body (pr-str (companies/upsert id edn-params))
|
||||
:headers {"Content-Type" "application/edn"}})
|
||||
|
||||
(PUT "/api/vendors/:id" {:keys [edn-params] {:keys [id]} :route-params :as r}
|
||||
{:status 200
|
||||
:body (pr-str (vendors/upsert id edn-params))
|
||||
:headers {"Content-Type" "application/edn"}})
|
||||
|
||||
(POST "/api/invoices" {:keys [edn-params]}
|
||||
(invoices/insert-multi! (:rows edn-params))
|
||||
{:status 200
|
||||
|
||||
Reference in New Issue
Block a user