28 lines
581 B
Go
28 lines
581 B
Go
package service
|
|
|
|
import (
|
|
"encoding/json"
|
|
|
|
"affiliate_dash/internal/model"
|
|
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
func writeAudit(tx *gorm.DB, merchantID, actorUserID, apiClientID *uint, action, entityType, entityID string, metadata interface{}) error {
|
|
raw := ""
|
|
if metadata != nil {
|
|
if bytes, err := json.Marshal(metadata); err == nil {
|
|
raw = string(bytes)
|
|
}
|
|
}
|
|
return tx.Create(&model.AuditLog{
|
|
MerchantID: merchantID,
|
|
ActorUserID: actorUserID,
|
|
APIClientID: apiClientID,
|
|
Action: action,
|
|
EntityType: entityType,
|
|
EntityID: entityID,
|
|
Metadata: raw,
|
|
}).Error
|
|
}
|