first commit
This commit is contained in:
23
backend/internal/calendar/audit.go
Normal file
23
backend/internal/calendar/audit.go
Normal file
@@ -0,0 +1,23 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user