Line data Source code
1 4 : (ns matchscore.domain.template.entity
2 : (:require
3 : [schemas.domain.templates :as template-schemas]))
4 :
5 :
6 4 : (def updatable-fields
7 92 : [:name
8 : :description
9 : :club-id
10 : :club-ids
11 : :sport-code
12 : :activity-type-code
13 : :state
14 : :visibility
15 : :fee
16 : :fee-type
17 : :currency
18 : :timezone
19 : :language
20 : :duration
21 : :score-entry-mode
22 : :score-entry-default
23 : :automatic-event-creation
24 : :automatic-event-creation-delay-minutes
25 : :rrule
26 : :rrule-json
27 : :ruleset-id
28 : :settings])
29 :
30 :
31 4 : (defn make-template
32 : "Creates a validated EventTemplate map."
33 : [data & [from-qualified]]
34 8 : (if from-qualified
35 12 : (template-schemas/make-template-record-from-qualified data)
36 0 : (template-schemas/make-template-record data)))
37 :
38 :
39 4 : (defn- normalize-numerics
40 : [m]
41 6 : (reduce-kv
42 3 : (fn [acc k v]
43 36 : (assoc acc k (if (number? v) (bigdec v) v)))
44 3 : {}
45 3 : m))
46 :
47 :
48 4 : (defn has-changes?
49 : "Returns true if any updatable field present in updates differs from existing."
50 : [existing updates]
51 6 : (not=
52 18 : (normalize-numerics (select-keys existing updatable-fields))
53 27 : (normalize-numerics (select-keys (merge existing updates) updatable-fields))))
54 :
55 :
56 4 : (defn merge-updates
57 : "Merges updatable fields from updates into existing account."
58 : [existing updates]
59 21 : (merge existing (select-keys updates updatable-fields)))
|