fix collection quantity add/remove to work properly when quality is nil

This commit is contained in:
Gered 2016-08-01 15:33:31 -04:00
parent 6265c390ae
commit cd3cb45213

View file

@ -16,14 +16,24 @@
(if-not (first (jdbc/query dt ["select count(*) from lists where id = ? and is_public in (true, ?)" list-id public-only?])) (if-not (first (jdbc/query dt ["select count(*) from lists where id = ? and is_public in (true, ?)" list-id public-only?]))
(throw (new Exception (str "Not authorized to update list:" list-id))) (throw (new Exception (str "Not authorized to update list:" list-id)))
(let [num-updates (first (let [num-updates (first
(vexec! view-system dt ; i love that SQL forces you to use "is null" ...
["update collection (if (nil? quality)
set quantity = quantity + ? (vexec! view-system dt
where card_id = ? and ["update collection
quality = ? and set quantity = quantity + ?
foil = ? and where card_id = ? and
list_id = ?" quality is null and
quantity-change card-id quality foil? list-id]))] foil = ? and
list_id = ?"
quantity-change card-id foil? list-id])
(vexec! view-system dt
["update collection
set quantity = quantity + ?
where card_id = ? and
quality = ? and
foil = ? and
list_id = ?"
quantity-change card-id quality foil? list-id])))]
(if (= 0 num-updates) (if (= 0 num-updates)
(first (first
(vexec! view-system dt (vexec! view-system dt