Skip to content

Commit

Permalink
create changelog on update
Browse files Browse the repository at this point in the history
  • Loading branch information
timohuber committed Dec 17, 2024
1 parent ea74883 commit 5a3d5ad
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 37 deletions.
37 changes: 13 additions & 24 deletions pool/app/settings/event.ml
Original file line number Diff line number Diff line change
Expand Up @@ -14,36 +14,25 @@ type event =
| PageScriptUpdated of (PageScript.t option * PageScript.location)
[@@deriving eq, show]

let[@warning "-27"] handle_event ?user_uuid pool : event -> unit Lwt.t
=
(* let open Utils.Lwt_result.Infix in *)
(* let create_changelog key after =
let open Version_history in
let%lwt before = Repo.find_by_key pool key ||> fun { value; _ } -> value in
let%lwt entity_uuid = Repo.find_setting_id pool key in
insert pool ?user_uuid ~entity_uuid ~before ~after ()
in
let handle_update key setting =
let%lwt () = create_changelog key setting in
Repo.update pool setting
in *)
function
| LanguagesUpdated languages -> Repo.TenantLanguages.update pool languages
| EmailSuffixesUpdated suffixes -> Repo.TenantEmailSuffixes.update pool suffixes
let handle_event ?user_uuid pool : event -> unit Lwt.t = function
| LanguagesUpdated languages -> Repo.TenantLanguages.update ?user_uuid pool languages
| EmailSuffixesUpdated suffixes ->
Repo.TenantEmailSuffixes.update ?user_uuid pool suffixes
| DefaultReminderLeadTimeUpdated lead_time ->
Repo.DefaultReminderLeadTime.update pool lead_time
Repo.DefaultReminderLeadTime.update ?user_uuid pool lead_time
| DefaultTextMsgReminderLeadTimeUpdated lead_time ->
Repo.DefaultTextMsgReminderLeadTime.update pool lead_time
| ContactEmailUpdated contact_email -> Repo.TenantContactEmail.update pool contact_email
Repo.DefaultTextMsgReminderLeadTime.update ?user_uuid pool lead_time
| ContactEmailUpdated contact_email ->
Repo.TenantContactEmail.update ?user_uuid pool contact_email
| InactiveUserDisableAfterUpdated disable_after ->
Repo.InactiveUserDisableAfter.update pool disable_after
Repo.InactiveUserDisableAfter.update ?user_uuid pool disable_after
| InactiveUserWarningUpdated warning_after ->
Repo.InactiveUserWarning.update pool warning_after
Repo.InactiveUserWarning.update ?user_uuid pool warning_after
| TriggerProfileUpdateAfterUpdated trigger_after ->
Repo.TriggerProfileUpdateAfter.update pool trigger_after
Repo.TriggerProfileUpdateAfter.update ?user_uuid pool trigger_after
| UserImportFirstReminderAfterUpdated first_reminder_after ->
Repo.UserImportFirstReminder.update pool first_reminder_after
Repo.UserImportFirstReminder.update ?user_uuid pool first_reminder_after
| UserImportSecondReminderAfterUpdated second_reminder_after ->
Repo.UserImportSecondReminder.update pool second_reminder_after
Repo.UserImportSecondReminder.update ?user_uuid pool second_reminder_after
| PageScriptUpdated script -> Repo.PageScripts.update pool script
;;
23 changes: 20 additions & 3 deletions pool/app/settings/repo/repo.ml
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,27 @@ end
module SettingRepo (T : SettingRepoSig) = struct
include T

let t = make_caqti ~encode:yojson_of_t ~decode:t_of_yojson
let find pool = Sql.find pool t key
module Changelog = Changelog.T (struct
include Changelog.DefaultSettings
include T

let model = Pool_message.Field.Setting
end)

let caqti_type = make_caqti ~encode:yojson_of_t ~decode:t_of_yojson
let find pool = Sql.find pool caqti_type key
let find_id pool = Sql.find_setting_id pool key
let update pool = Sql.exec_update pool t key

let create_changelog ?user_uuid pool after =
let%lwt before = find pool in
let%lwt entity_uuid = Sql.find_setting_id pool key in
Changelog.insert pool ?user_uuid ~entity_uuid ~before ~after ()
;;

let update ?user_uuid pool m =
let%lwt () = create_changelog ?user_uuid pool m in
Sql.exec_update pool caqti_type key m
;;
end

module DefaultReminderLeadTime = SettingRepo (EmailReminderLeadTime)
Expand Down
10 changes: 0 additions & 10 deletions pool/app/settings/version_history.ml

This file was deleted.

0 comments on commit 5a3d5ad

Please sign in to comment.