Setting up initial company setup.
This commit is contained in:
8
docker-compose.prod.yml
Normal file
8
docker-compose.prod.yml
Normal file
@@ -0,0 +1,8 @@
|
||||
version: '2'
|
||||
services:
|
||||
app:
|
||||
ports:
|
||||
- 80:3000
|
||||
restart: always
|
||||
database:
|
||||
restart: always
|
||||
1
migrator/migrations/1522800061-DOWN.sql
Normal file
1
migrator/migrations/1522800061-DOWN.sql
Normal file
@@ -0,0 +1 @@
|
||||
DROP TABLE companies (id serial primary key, name varchar(255), data text);
|
||||
8
migrator/migrations/1522800061-UP.sql
Normal file
8
migrator/migrations/1522800061-UP.sql
Normal file
@@ -0,0 +1,8 @@
|
||||
-- 1522800061 UP
|
||||
CREATE TABLE companies (id serial primary key, name varchar(255), data text);
|
||||
|
||||
insert into companies (name, data) values ('Campbell Brewing Company', '{:matches ["campbell brewing company" "campbell brewery company" "campbell brewing"]}');
|
||||
|
||||
insert into companies (name, data) values ('Brown Chicken Brown Cow', '{:matches ["brown chicken brown cow"]}');
|
||||
|
||||
insert into companies (name, data) values ('Naschmarkt Restaurant', '{:matches ["naschmarkt" "naschmarkt restaurant"]}');
|
||||
@@ -4,18 +4,15 @@
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
"db-migrate": "db-migrate",
|
||||
"db-rollback": "db-rollback",
|
||||
"db-create": "db-create",
|
||||
"db-status": "db-status"
|
||||
},
|
||||
"author": "Bryce Covert <bryce.covert@nordstrom.com>",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"db-migrator": "^2.2.0",
|
||||
"pg": "^7.4.0"
|
||||
},
|
||||
"scripts": {
|
||||
"db-migrate": "db-migrate",
|
||||
"db-rollback": "db-rollback",
|
||||
"db-create": "db-create",
|
||||
"db-status": "db-status"
|
||||
}
|
||||
}
|
||||
|
||||
BIN
resources/public alias
Normal file
BIN
resources/public alias
Normal file
Binary file not shown.
@@ -1,9 +1,10 @@
|
||||
(ns auto-ap.db.companies)
|
||||
(ns auto-ap.db.companies
|
||||
(:require [clojure.java.jdbc :as j]
|
||||
[auto-ap.db.utils :refer [clj->db db->clj get-conn]]
|
||||
[clojure.edn :as edn]))
|
||||
|
||||
(defn get-all []
|
||||
[{:name "Campbell Brewing Company"
|
||||
:matches ["campbell brewing company" "campbell brewery company" "campbell brewing"]}
|
||||
{:name "Brown Chicken Brown Cow"
|
||||
:matches ["brown chicken brown cow"]}
|
||||
{:name "Naschmarkt Restaurant"
|
||||
:matches ["naschmarkt" "naschmarkt restaurant"]}])
|
||||
(->> (j/query (get-conn) "SELECT * FROM companies")
|
||||
(map db->clj )
|
||||
(map (fn [{:keys [data] :as x}]
|
||||
(merge x (edn/read-string data))))))
|
||||
|
||||
@@ -80,6 +80,11 @@
|
||||
|
||||
(defroutes api-routes
|
||||
|
||||
(GET "/api/companies" []
|
||||
{:status 200
|
||||
:body (pr-str (companies/get-all))
|
||||
:headers {"Content-Type" "application/edn"}})
|
||||
|
||||
(GET "/api/invoices" []
|
||||
{:status 200
|
||||
:body (pr-str (invoices/get-all))
|
||||
@@ -119,6 +124,7 @@
|
||||
(let [{:keys [filename tempfile]} files
|
||||
existing-invoices (invoices/get-all)
|
||||
companies (companies/get-all)]
|
||||
(println companies)
|
||||
(invoices/insert-multi!
|
||||
(for [{:keys [total date invoice-number customer-identifier vendor] :as row}
|
||||
(parse/parse-file (.getPath tempfile) filename)]
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
(let [headers (if token
|
||||
(assoc headers "Authorization" (str "Token " token))
|
||||
headers)]
|
||||
(println headers)
|
||||
(->> (http/request {:method method
|
||||
:body body
|
||||
:headers headers
|
||||
|
||||
@@ -16,17 +16,30 @@
|
||||
:user token)}
|
||||
{:db (assoc db/default-db
|
||||
:active-page handler
|
||||
:user token)}))))
|
||||
:user token)
|
||||
:http {:method :get
|
||||
:token token
|
||||
:uri (str "/api/companies")
|
||||
:on-success [::received-companies]}}))))
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::toggle-menu
|
||||
(fn [db [_ which]]
|
||||
(update-in db [:menu which :active?] #(not %))))
|
||||
|
||||
(re-frame/reg-event-db
|
||||
(re-frame/reg-event-fx
|
||||
::logged-in
|
||||
(fn [db [_ token user]]
|
||||
(assoc db :user (assoc user :token token))))
|
||||
(fn [{:keys [db]} [_ token user]]
|
||||
{:http {:method :get
|
||||
:token token
|
||||
:uri (str "/api/companies")
|
||||
:on-success [::received-companies]}
|
||||
:db (assoc db :user (assoc user :token token))}))
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::received-companies
|
||||
(fn [db [_ companies]]
|
||||
(assoc db :companies companies)))
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::swap-company
|
||||
|
||||
@@ -12,8 +12,7 @@
|
||||
::companies
|
||||
(fn [db]
|
||||
(when (:user db)
|
||||
(let [{:strs [companies] :as x} (js->clj (.parse js/JSON (base64/decodeString (second (str/split (:user db) #"\.")))))]
|
||||
(map (fn [c] {:name c}) companies)))))
|
||||
(:companies db))))
|
||||
|
||||
(re-frame/reg-sub
|
||||
::menu
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
[:a {:class "navbar-link login" :on-click (fn [e] (re-frame/dispatch [::events/toggle-menu :account]))} (:name @user)]
|
||||
[:div {:class "navbar-dropdown"}
|
||||
[:a {:class "navbar-item"} "My profile"]
|
||||
[:a {:class "navbar-item"} "Administration"]
|
||||
[:hr {:class "navbar-divider"}]
|
||||
[:a.navbar-item {:on-click (fn [e] (.preventDefault e) (re-frame/dispatch [::events/logout]))} "Logout"]]]
|
||||
[:a.navbar-item {:href login-url} "Login"])]]))
|
||||
|
||||
Reference in New Issue
Block a user