Skip to content

Instantly share code, notes, and snippets.

@mbertheau
Created January 8, 2016 15:32
Show Gist options
  • Save mbertheau/ebdf995dc3c635e1f55e to your computer and use it in GitHub Desktop.
Save mbertheau/ebdf995dc3c635e1f55e to your computer and use it in GitHub Desktop.
(defn ^:export init [js-product-form-data]
(let [product-form-data (js->clj js-product-form-data :keywordize-keys true)
contains-in? (fn [m [k & ks]]
(if (contains? m k)
(if (nil? ks)
true
(recur (get m k) ks))
false))
update-in-maybe (fn [m ks f] (if (contains-in? m ks)
(update-in m ks f)
m))
product (-> product-form-data
:product
(update-in-maybe [:what :product-class] keyword)
(update-in-maybe [:when :volatility] keyword)
(update-in-maybe [:when :occasion] keyword)
(update-in-maybe [:when :cohesion] keyword)
(update-in-maybe [:when :first-day :choice] keyword)
(update-in-maybe [:when :last-day :choice] keyword)
(update-in-maybe [:for-whom :audience-size] keyword)
(update-in-maybe [:for-whom :min-participants :choice] keyword)
(update-in-maybe [:for-whom :max-participants :choice] keyword)
(update-in-maybe [:for-whom :places-of-business] set)
(update-in-maybe [:where :location-type] keyword)
(update-in-maybe [:who :contact-salutation] keyword)
(update-in-maybe [:how-much :amount] h/clean-amount)
(update-in-maybe [:how-much :vat-rate] keyword)
(update-in-maybe [:when :first-day :value] h/iso-date->human)
(update-in-maybe [:when :last-day :value] h/iso-date->human)
(update-in-maybe
[:when :schedules]
(fn [schedules]
(->> schedules
(mapv #(update-in-maybe % [:registration-deadline] h/iso-date->human))
(mapv #(update-in-maybe % [:appointments]
(partial mapv (fn [appointment]
(-> appointment
(update :date h/iso-date->human)
(update :time h/iso-time->human))))))))))]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment