24 lines
608 B
Go
24 lines
608 B
Go
package calendar
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
)
|
|
|
|
func (s Store) RecordAudit(ctx context.Context, actorUserID string, action string, entityType string, entityID string, metadata map[string]any) error {
|
|
payload := "{}"
|
|
if metadata != nil {
|
|
bytes, err := json.Marshal(metadata)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
payload = string(bytes)
|
|
}
|
|
|
|
_, err := s.db.Exec(ctx, `
|
|
INSERT INTO audit_logs (actor_user_id, action, entity_type, entity_id, metadata)
|
|
VALUES (NULLIF($1, '')::uuid, $2, $3, NULLIF($4, '')::uuid, $5::jsonb)
|
|
`, actorUserID, action, entityType, entityID, payload)
|
|
return err
|
|
}
|