Skip to content

Commit

Permalink
Merge pull request #911 from CSCfi/create-catalogue-item-disabled
Browse files Browse the repository at this point in the history
Create catalogue item disabled
  • Loading branch information
foxlynx committed Feb 11, 2019
2 parents 88c0406 + d99bfcb commit 5071adc
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 8 deletions.
10 changes: 8 additions & 2 deletions resources/sql/queries.sql
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,14 @@ WHERE ci.id = :item
-- :name create-catalogue-item! :insert
-- :doc Create a single catalogue item
INSERT INTO catalogue_item
(title, formid, resid, wfid)
VALUES (:title, :form, :resid, :wfid)
(title, formid, resid, wfid, state)
VALUES (:title, :form, :resid, :wfid,
/*~ (if (:state params) */
CAST(:state as item_state)
/*~*/
'enabled'
/*~ ) ~*/
)

-- :name get-resources :? :*
SELECT
Expand Down
3 changes: 2 additions & 1 deletion src/clj/rems/api/catalogue_items.clj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
{:title s/Str
:form s/Num
:resid s/Num
:wfid s/Num})
:wfid s/Num
(s/optional-key :state) (s/maybe s/Str)})

(s/defschema CreateCatalogueItemResponse
CatalogueItem)
Expand Down
2 changes: 1 addition & 1 deletion src/clj/rems/db/catalogue.clj
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
(localize-catalogue-item item)))

(defn create-catalogue-item! [command]
(let [id (:id (db/create-catalogue-item! (select-keys command [:title :form :resid :wfid])))]
(let [id (:id (db/create-catalogue-item! (select-keys command [:title :form :resid :wfid :state])))]
(get-localized-catalogue-item id)))

(defn create-catalogue-item-localization! [command]
Expand Down
7 changes: 6 additions & 1 deletion src/cljs/rems/administration/create_catalogue_item.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,13 @@
(when (valid-request? request)
request)))

(defn- create-request-with-state [request]
(if (nil? (:state request))
(merge {:state "disabled"} request)
request))

(defn- create-catalogue-item [request]
(post! "/api/catalogue-items/create" {:params request
(post! "/api/catalogue-items/create" {:params (create-request-with-state request)
;; TODO error handling
:handler (fn [resp] (dispatch! "#/administration/catalogue-items"))}))

Expand Down
3 changes: 2 additions & 1 deletion test/clj/rems/test/api/applications.clj
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,8 @@
(json-body {:title ""
:form form-id
:resid 1
:wfid 1})
:wfid 1
:state "enabled"})
app
read-ok-body
:id))
Expand Down
3 changes: 2 additions & 1 deletion test/clj/rems/test/api/catalogue_items.clj
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
(json-body {:title "test-item-title"
:form 1
:resid 1
:wfid 1})
:wfid 1
:state "enabled"})
app
read-body)]
(is (= 11 (:id data))))
Expand Down
3 changes: 2 additions & 1 deletion test/clj/rems/test/api/forms.clj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
(json-body {:title "tmp"
:form form-id
:resid 1
:wfid 1})
:wfid 1
:state "enabled"})
app
assert-response-is-ok
read-body)
Expand Down

0 comments on commit 5071adc

Please sign in to comment.