refactor: alerts / emails

This commit is contained in:
Henry Dollman
2024-08-12 19:13:42 -04:00
parent d0d4e546d9
commit f8d2161489
6 changed files with 32 additions and 57 deletions

View File

@@ -46,9 +46,8 @@ func NewHub(app *pocketbase.PocketBase) *Hub {
}
func (h *Hub) Run() {
rm := records.NewRecordManager(h.app)
am := alerts.NewAlertManager(h.app)
var rm *records.RecordManager
var am *alerts.AlertManager
// loosely check if it was executed using "go run"
isGoRun := strings.HasPrefix(os.Args[0], os.TempDir())
@@ -60,6 +59,13 @@ func (h *Hub) Run() {
Dir: "../../migrations",
})
// set up record manager and alert manager
h.app.OnBeforeServe().Add(func(e *core.ServeEvent) error {
rm = records.NewRecordManager(h.app)
am = alerts.NewAlertManager(h.app)
return nil
})
// set auth settings
h.app.OnBeforeServe().Add(func(e *core.ServeEvent) error {
usersCollection, err := h.app.Dao().FindCollectionByNameOrId("users")