LCOV - code coverage report
Current view: top level - matchscore/domain/telegram_link - query.clj Coverage Total Hit
Test: lcov.info Lines: 100.0 % 22 22
Test Date: 2026-11-23 18:11:10 Functions: - 0 0

            Line data    Source code
       1            4 : (ns matchscore.domain.telegram-link.query
       2              :   (:require
       3              :    [matchscore.db.postgres.telegram-links :as telegram-links-db]
       4              :    [matchscore.domain.event-telegram-link.repository.postgres :as event-telegram-link-postgres-repo]
       5              :    [matchscore.domain.template-telegram-link.repository.postgres
       6              :     :as
       7              :     template-telegram-link-postgres-repo]))
       8              : 
       9              : 
      10            4 : (defn resolve-links-for-event
      11              :  "Returns the effective telegram links for an event.
      12              :    Event-level links take precedence; falls back to template-level
      13              :    links when no event-level links exist and the event has a template-id.
      14              :    Each link map is augmented with :kind (:event or :template)."
      15              :  [{:keys [repos]} event]
      16           12 :  (let [event-links (event-telegram-link-postgres-repo/find-by-event-id
      17           12 :                     (:event-telegram-link-postgres-repo repos)
      18           12 :                     (:uuid event))]
      19           16 :    (if (seq event-links)
      20           36 :      (mapv #(assoc % :kind :event) event-links)
      21           10 :      (when (:template-id event)
      22            2 :        (->>
      23            4 :          (template-telegram-link-postgres-repo/find-by-template-id
      24            6 :           (:template-telegram-link-postgres-repo repos)
      25            6 :           (:template-id event))
      26           14 :          (mapv #(assoc % :kind :template)))))))
      27              : 
      28              : 
      29           19 : (defn- links-ds [repos] (:ds (:template-telegram-link-postgres-repo repos)))
      30              : 
      31              : 
      32            4 : (defn list-links-for-owner
      33              :  "Returns every Telegram link on templates and events the user manages, with the
      34              :    resource summary, latest bot post and last delivery failure on each. See
      35              :    `matchscore.db.postgres.telegram-links/links`."
      36              :  [repos user-id]
      37           12 :  (telegram-links-db/links (links-ds repos) user-id))
      38              : 
      39              : 
      40            4 : (defn list-links-for-resource
      41              :  "Returns the Telegram links of one template or event (`kind` is :template or
      42              :    :event) with the latest bot post and last delivery failure on each."
      43              :  [repos kind resource-id]
      44           14 :  (telegram-links-db/resource-links (links-ds repos) kind resource-id))
      45              : 
      46              : 
      47            4 : (defn list-all-links
      48              :  "Returns every Telegram link on the platform, in the same shape as
      49              :    `list-links-for-owner`."
      50              :  [repos]
      51           10 :  (telegram-links-db/links (links-ds repos)))
      52              : 
      53              : 
      54            4 : (defn list-unlinked-for-owner
      55              :  "Returns the active templates and upcoming standalone events the user created
      56              :    that have no Telegram link yet."
      57              :  [repos user-id]
      58           12 :  (telegram-links-db/unlinked-resources (links-ds repos) user-id))
        

Generated by: LCOV version 2.0-1