Setting up initial company setup.

This commit is contained in:
Bryce Covert
2018-04-03 18:19:51 -07:00
parent 222bcbdf5c
commit b810deb609
11 changed files with 55 additions and 20 deletions

8
docker-compose.prod.yml Normal file
View File

@@ -0,0 +1,8 @@
version: '2'
services:
app:
ports:
- 80:3000
restart: always
database:
restart: always

View File

@@ -0,0 +1 @@
DROP TABLE companies (id serial primary key, name varchar(255), data text);

View 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"]}');

View File

@@ -4,18 +4,15 @@
"description": "", "description": "",
"main": "index.js", "main": "index.js",
"scripts": { "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>", "author": "Bryce Covert <bryce.covert@nordstrom.com>",
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"db-migrator": "^2.2.0", "db-migrator": "^2.2.0",
"pg": "^7.4.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

Binary file not shown.

View File

@@ -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 [] (defn get-all []
[{:name "Campbell Brewing Company" (->> (j/query (get-conn) "SELECT * FROM companies")
:matches ["campbell brewing company" "campbell brewery company" "campbell brewing"]} (map db->clj )
{:name "Brown Chicken Brown Cow" (map (fn [{:keys [data] :as x}]
:matches ["brown chicken brown cow"]} (merge x (edn/read-string data))))))
{:name "Naschmarkt Restaurant"
:matches ["naschmarkt" "naschmarkt restaurant"]}])

View File

@@ -79,6 +79,11 @@
(routes (ANY "*" [] (response/resource-response "index.html" {:root "public"})))) (routes (ANY "*" [] (response/resource-response "index.html" {:root "public"}))))
(defroutes api-routes (defroutes api-routes
(GET "/api/companies" []
{:status 200
:body (pr-str (companies/get-all))
:headers {"Content-Type" "application/edn"}})
(GET "/api/invoices" [] (GET "/api/invoices" []
{:status 200 {:status 200
@@ -119,6 +124,7 @@
(let [{:keys [filename tempfile]} files (let [{:keys [filename tempfile]} files
existing-invoices (invoices/get-all) existing-invoices (invoices/get-all)
companies (companies/get-all)] companies (companies/get-all)]
(println companies)
(invoices/insert-multi! (invoices/insert-multi!
(for [{:keys [total date invoice-number customer-identifier vendor] :as row} (for [{:keys [total date invoice-number customer-identifier vendor] :as row}
(parse/parse-file (.getPath tempfile) filename)] (parse/parse-file (.getPath tempfile) filename)]

View File

@@ -26,6 +26,7 @@
(let [headers (if token (let [headers (if token
(assoc headers "Authorization" (str "Token " token)) (assoc headers "Authorization" (str "Token " token))
headers)] headers)]
(println headers)
(->> (http/request {:method method (->> (http/request {:method method
:body body :body body
:headers headers :headers headers

View File

@@ -16,17 +16,30 @@
:user token)} :user token)}
{:db (assoc db/default-db {:db (assoc db/default-db
:active-page handler :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 (re-frame/reg-event-db
::toggle-menu ::toggle-menu
(fn [db [_ which]] (fn [db [_ which]]
(update-in db [:menu which :active?] #(not %)))) (update-in db [:menu which :active?] #(not %))))
(re-frame/reg-event-db (re-frame/reg-event-fx
::logged-in ::logged-in
(fn [db [_ token user]] (fn [{:keys [db]} [_ token user]]
(assoc db :user (assoc user :token token)))) {: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 (re-frame/reg-event-db
::swap-company ::swap-company

View File

@@ -12,8 +12,7 @@
::companies ::companies
(fn [db] (fn [db]
(when (:user db) (when (:user db)
(let [{:strs [companies] :as x} (js->clj (.parse js/JSON (base64/decodeString (second (str/split (:user db) #"\.")))))] (:companies db))))
(map (fn [c] {:name c}) companies)))))
(re-frame/reg-sub (re-frame/reg-sub
::menu ::menu

View File

@@ -27,6 +27,7 @@
[:a {:class "navbar-link login" :on-click (fn [e] (re-frame/dispatch [::events/toggle-menu :account]))} (:name @user)] [:a {:class "navbar-link login" :on-click (fn [e] (re-frame/dispatch [::events/toggle-menu :account]))} (:name @user)]
[:div {:class "navbar-dropdown"} [:div {:class "navbar-dropdown"}
[:a {:class "navbar-item"} "My profile"] [:a {:class "navbar-item"} "My profile"]
[:a {:class "navbar-item"} "Administration"]
[:hr {:class "navbar-divider"}] [:hr {:class "navbar-divider"}]
[:a.navbar-item {:on-click (fn [e] (.preventDefault e) (re-frame/dispatch [::events/logout]))} "Logout"]]] [:a.navbar-item {:on-click (fn [e] (.preventDefault e) (re-frame/dispatch [::events/logout]))} "Logout"]]]
[:a.navbar-item {:href login-url} "Login"])]])) [:a.navbar-item {:href login-url} "Login"])]]))