implemented crud
This commit is contained in:
@@ -12,7 +12,7 @@
|
||||
[clj-time.core :as time]
|
||||
[clj-time.coerce :as coerce]))
|
||||
|
||||
(def uri "datomic:sql://invoices-backup?jdbc:postgresql://database:5432/datomic?user=datomic&password=datomic")
|
||||
(def uri "datomic:sql://invoices?jdbc:postgresql://database:5432/datomic?user=datomic&password=datomic")
|
||||
|
||||
(defn create-database []
|
||||
(d/create-database uri))
|
||||
|
||||
@@ -20,12 +20,15 @@
|
||||
:args [db]}
|
||||
(:sort-by args) (add-sorter-field {"client" ['[?e :transaction-rule/client ?c]
|
||||
'[?c :client/name ?sorter]]
|
||||
|
||||
"yodlee-merchant" ['[?e :transaction-rule/yodlee-merchant ?c]
|
||||
'[?c :yodlee-merchant/name ?sorter]]
|
||||
"bank-account" ['[?e :transaction-rule/bank-account ?c]
|
||||
'[?c :bank-account/name ?sorter]]
|
||||
"amount_lte" ['[?e :transaction-rule/amount-lte ?sorter]]
|
||||
"amount_gte" ['[?e :transaction-rule/amount-gte ?sorter]]
|
||||
"description" ['[?e :transaction-rule/description ?sorter]]
|
||||
"note" ['[?e :transaction-rule/note ?sorter]]
|
||||
"amount-lte" ['[?e :transaction-rule/amount-lte ?sorter]]
|
||||
"amount-gte" ['[?e :transaction-rule/amount-gte ?sorter]]
|
||||
}
|
||||
args)
|
||||
|
||||
|
||||
@@ -39,7 +39,14 @@
|
||||
:ident {:parse (schema/as-conformer (fn [x] {:db/ident x}))
|
||||
:serialize (schema/as-conformer #(or (:ident %) (:db/ident %) %))}
|
||||
:iso_date {:parse (schema/as-conformer #(time/parse % time/iso-date))
|
||||
:serialize (schema/as-conformer #(time/unparse % time/iso-date))}}
|
||||
:serialize (schema/as-conformer #(time/unparse % time/iso-date))}
|
||||
:money {:parse (schema/as-conformer #(if (string? %)
|
||||
(Double/parseDouble %)
|
||||
%))
|
||||
:serialize (schema/as-conformer #(if (double? %)
|
||||
(str %)
|
||||
%))
|
||||
}}
|
||||
:objects
|
||||
{
|
||||
:client
|
||||
@@ -493,6 +500,15 @@
|
||||
:vendor_id {:type :id}
|
||||
:accounts {:type '(list :edit_expense_account)}}}
|
||||
|
||||
:edit_transaction_rule
|
||||
{:fields {:id {:type :id}
|
||||
:description {:type 'String}
|
||||
:note {:type 'String}
|
||||
:bank_account_id {:type :id}
|
||||
:client_id {:type :id}
|
||||
:amount_lte {:type :money}
|
||||
:amount_gte {:type :money}}}
|
||||
|
||||
:edit_account
|
||||
{:fields {:id {:type :id}
|
||||
:type {:type :account_type}
|
||||
@@ -552,6 +568,10 @@
|
||||
:upsert_vendor {:type :vendor
|
||||
:args {:vendor {:type :add_vendor}}
|
||||
:resolve :mutation/upsert-vendor}
|
||||
|
||||
:upsert_transaction_rule {:type :transaction_rule
|
||||
:args {:transaction_rule {:type :edit_transaction_rule}}
|
||||
:resolve :mutation/upsert-transaction-rule}
|
||||
:add_invoice {:type :invoice
|
||||
:args {:invoice {:type :add_invoice}}
|
||||
:resolve :mutation/add-invoice}
|
||||
@@ -739,6 +759,7 @@
|
||||
:mutation/add-and-print-invoice gq-invoices/add-and-print-invoice
|
||||
:mutation/edit-invoice gq-invoices/edit-invoice
|
||||
:mutation/edit-transaction gq-transactions/edit-transaction
|
||||
:mutation/upsert-transaction-rule gq-transaction-rules/upsert-transaction-rule
|
||||
:mutation/match-transaction gq-transactions/match-transaction
|
||||
:mutation/edit-client gq-clients/edit-client
|
||||
:mutation/upsert-vendor gq-vendors/upsert-vendor
|
||||
|
||||
@@ -1,8 +1,28 @@
|
||||
(ns auto-ap.graphql.transaction-rules
|
||||
(:require [auto-ap.datomic.transaction-rules :as tr]
|
||||
[datomic.api :as d]
|
||||
[auto-ap.datomic :refer [remove-nils uri]]
|
||||
[auto-ap.graphql.utils :refer [->graphql <-graphql limited-clients assert-admin result->page]]))
|
||||
|
||||
(defn get-transaction-rule-page [context args value]
|
||||
(let [args (assoc args :id (:id context))
|
||||
[journal-entries journal-entries-count] (tr/get-graphql (<-graphql args))]
|
||||
(result->page journal-entries journal-entries-count :transaction_rules args)))
|
||||
|
||||
(defn upsert-transaction-rule [context {{:keys [id description note client_id bank_account_id amount_lte amount_gte ]} :transaction_rule :as z} value]
|
||||
(let [transaction [(remove-nils #:transaction-rule {:db/id (if id
|
||||
id
|
||||
"transaction-rule")
|
||||
:description description
|
||||
:note note
|
||||
:client client_id
|
||||
:bank-account bank_account_id
|
||||
:amount-lte amount_lte
|
||||
:amount-gte amount_gte})]
|
||||
_ (println transaction)
|
||||
transaction-result @(d/transact (d/connect uri) transaction)]
|
||||
(println "HI" (or (-> transaction-result )
|
||||
id))
|
||||
(-> (tr/get-by-id (or (-> transaction-result :tempids (get "transaction-rule"))
|
||||
id))
|
||||
(->graphql))))
|
||||
|
||||
Reference in New Issue
Block a user