Skip to content

Commit

Permalink
kruto
Browse files Browse the repository at this point in the history
  • Loading branch information
Satont committed Oct 15, 2024
1 parent 84068f0 commit 3b3a8cb
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 16 deletions.
13 changes: 13 additions & 0 deletions apps/api-gql/internal/gql/mappers/audit-logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,16 @@ func AuditTypeModelToGql(t model.AuditOperationType) gqlmodel.AuditOperationType
return ""
}
}

func AuditTypeGqlToModel(t gqlmodel.AuditOperationType) model.AuditOperationType {
switch t {
case gqlmodel.AuditOperationTypeUpdate:
return model.AuditOperationUpdate
case gqlmodel.AuditOperationTypeCreate:
return model.AuditOperationCreate
case gqlmodel.AuditOperationTypeDelete:
return model.AuditOperationDelete
default:
return ""
}
}
21 changes: 14 additions & 7 deletions apps/api-gql/internal/gql/resolvers/admin-audit-logs.resolver.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions apps/api-gql/schema/admin-audit-logs.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ input AdminAuditLogsInput {
table: String
objectId: String
userId: String
dashboardId: String
channelId: String
operationType: AuditOperationType
page: Int
perPage: Int
Expand All @@ -20,11 +20,11 @@ type AdminAuditLog {
newValue: String
objectId: String
userId: String
dashboardId: String
channelId: String
createdAt: Time!

user: TwirUserTwitchInfo @goField(forceResolver: true)
dashboardUser: TwirUserTwitchInfo @goField(forceResolver: true)
channel: TwirUserTwitchInfo @goField(forceResolver: true)
}

enum AuditOperationType {
Expand Down
6 changes: 3 additions & 3 deletions libs/baseapp/gorm-audit-hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (c *gormAuditHooks) create(tx *gorm.DB) {
NewValue: null.StringFrom(prepareData(recordMap)),
ObjectID: null.StringFrom(objId),
UserID: null.StringFromPtr(userID),
DashboardID: null.StringFromPtr(dashboardID),
ChannelID: null.StringFromPtr(dashboardID),
}

if err := tx.Session(
Expand Down Expand Up @@ -79,7 +79,7 @@ func (c *gormAuditHooks) delete(tx *gorm.DB) {
OldValue: null.StringFrom(prepareData(recordMap)),
ObjectID: null.StringFrom(objId),
UserID: null.StringFromPtr(userID),
DashboardID: null.StringFromPtr(dashboardID),
ChannelID: null.StringFromPtr(dashboardID),
}

if err := tx.Session(
Expand Down Expand Up @@ -118,7 +118,7 @@ func (c *gormAuditHooks) update(tx *gorm.DB) {
NewValue: null.StringFrom(prepareData(recordMap)),
ObjectID: null.StringFrom(objId),
UserID: null.StringFromPtr(userID),
DashboardID: null.StringFromPtr(dashboardID),
ChannelID: null.StringFromPtr(dashboardID),
}

if err := tx.Session(
Expand Down
6 changes: 3 additions & 3 deletions libs/gomodels/audit-log.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ type AuditLog struct {
OldValue null.String `gorm:"column:old_value;type:text"`
NewValue null.String `gorm:"column:new_value;type:text"`
ObjectID null.String `gorm:"column:object_id;type:uuid"`
ChannelID null.String `gorm:"column:channel_id;type:uuid"`
UserID null.String `gorm:"column:user_id;type:uuid"`
DashboardID null.String `gorm:"column:dashboard_id;type:uuid"`
CreatedAt time.Time `gorm:"column:created_at;type:timestamp;default:now()"`

User *Users `gorm:"foreignKey:UserID"`
Dashboard *Users `gorm:"foreignKey:DashboardID"`
Channel *Users `gorm:"foreignKey:ChannelID"`
User *Users `gorm:"foreignKey:UserID"`
}

func (c *AuditLog) TableName() string {
Expand Down

0 comments on commit 3b3a8cb

Please sign in to comment.