LCOV - code coverage report
Current view: top level - schemas/domain - event_participants.clj Coverage Total Hit
Test: lcov.info Lines: 59.7 % 67 40
Test Date: 2026-11-23 18:11:10 Functions: - 0 0

            Line data    Source code
       1            4 : (ns schemas.domain.event-participants
       2              :   (:require
       3              :    [malli.core :as m]
       4              :    [malli.error :as me]
       5              :    [schemas.api.common :as api-common]))
       6              : 
       7              : 
       8            4 : (def participant-statuses
       9              :   "Statuses a participant can hold in an event or one of its classes."
      10           28 :   ["registered" "confirmed" "checked_in" "withdrawn" "no_show" "disqualified"])
      11              : 
      12              : 
      13           24 : (def ParticipantStatusSchema (into [:enum] participant-statuses))
      14              : 
      15              : 
      16            4 : (def EventParticipantRecordSchema
      17           28 :   [:map {:swagger/title       "EventParticipantRecord"
      18              :          :swagger/description "Complete event participant record from database"}
      19           20 :    [:event-id [:ref :types/UuidString]]
      20           20 :    [:participant-id [:ref :types/UuidString]]
      21           20 :    [:seed {:optional true}
      22           28 :     [:maybe [:int {:min 1}]]]
      23           12 :    [:status ParticipantStatusSchema]
      24           12 :    [:registered-at api-common/Datetime]
      25           20 :    [:confirmed-at {:optional true}
      26           12 :     [:maybe api-common/Datetime]]
      27           20 :    [:checked-in-at {:optional true}
      28           12 :     [:maybe api-common/Datetime]]
      29           12 :    [:extra map?]
      30           12 :    [:created-datetime api-common/Datetime]
      31           12 :    [:updated-datetime api-common/Datetime]
      32           12 :    [:roles sequential?]
      33           12 :    [:attendance-confirmed :boolean]
      34           20 :    [:source [:ref :matchscore/source]]])
      35              : 
      36              : 
      37            4 : (defrecord
      38              :   EventParticipantRecord
      39              :   [event-id
      40              :    participant-id
      41              :    seed
      42              :    status
      43              :    registered-at
      44              :    confirmed-at
      45              :    checked-in-at
      46              :    extra
      47              :    created-datetime
      48              :    updated-datetime
      49              :    roles
      50              :    attendance-confirmed
      51              :    source])
      52              : 
      53              : 
      54            4 : (defn make-event-participant-record
      55              :  "Creates an EventParticipant record with validation.
      56              :    Note: This validation uses the default registry. Ensure schemas.registry/init-registry!
      57              :    has been called before using this function."
      58              :  {:malli/schema [:=> [:cat :map] EventParticipantRecordSchema]}
      59              :  [{:keys [event-id
      60              :           participant-id
      61              :           seed
      62              :           status
      63              :           registered-at
      64              :           confirmed-at
      65              :           checked-in-at
      66              :           extra
      67              :           created-datetime
      68              :           updated-datetime
      69              :           roles
      70              :           attendance-confirmed
      71              :           source]
      72              :    :as   participant-data}]
      73           20 :  (if (m/validate EventParticipantRecordSchema participant-data)
      74            8 :    (map->EventParticipantRecord
      75           60 :     {:event-id         event-id
      76            4 :      :participant-id   participant-id
      77            4 :      :seed             seed
      78           20 :      :status           (or status "registered")
      79            4 :      :registered-at    registered-at
      80            4 :      :confirmed-at     confirmed-at
      81            4 :      :checked-in-at    checked-in-at
      82           20 :      :extra            (or extra {})
      83            4 :      :created-datetime created-datetime
      84            4 :      :updated-datetime updated-datetime
      85           20 :      :roles            (or roles [])
      86           24 :      :attendance-confirmed (if (nil? attendance-confirmed) false attendance-confirmed)
      87           20 :      :source           (or source "matchscore")})
      88            0 :    (throw
      89            0 :     (ex-info
      90              :      "Invalid event participant data"
      91            0 :      {:type   :internal-validation-error
      92            0 :       :schema EventParticipantRecordSchema
      93            0 :       :data   participant-data
      94            0 :       :humanized-errors (me/humanize (m/explain EventParticipantRecordSchema participant-data))}))))
      95              : 
      96              : 
      97            4 : (defn make-event-participant-record-from-qualified
      98              :  "Creates an EventParticipant record from a map with :event-participants/* namespaced keys."
      99              :  [{:event-participants/keys [event-id
     100              :                              participant-id
     101              :                              seed
     102              :                              status
     103              :                              registered-at
     104              :                              confirmed-at
     105              :                              checked-in-at
     106              :                              extra
     107              :                              created-datetime
     108              :                              updated-datetime
     109              :                              roles
     110              :                              attendance-confirmed
     111              :                              source]}]
     112            0 :  (let [record {:event-id         event-id
     113            0 :                :participant-id   participant-id
     114            0 :                :seed             seed
     115            0 :                :status           status
     116            0 :                :registered-at    registered-at
     117            0 :                :confirmed-at     confirmed-at
     118            0 :                :checked-in-at    checked-in-at
     119            0 :                :extra            extra
     120            0 :                :created-datetime created-datetime
     121            0 :                :updated-datetime updated-datetime
     122            0 :                :roles            roles
     123            0 :                :attendance-confirmed attendance-confirmed
     124            0 :                :source           source}]
     125            0 :    (if (m/validate EventParticipantRecordSchema record)
     126            0 :      (map->EventParticipantRecord record)
     127            0 :      (throw
     128            0 :       (ex-info
     129              :        "Invalid event participant data"
     130            0 :        {:type   :internal-validation-error
     131            0 :         :schema EventParticipantRecordSchema
     132            0 :         :data   record
     133            0 :         :humanized-errors (me/humanize (m/explain EventParticipantRecordSchema record))})))))
        

Generated by: LCOV version 2.0-1