Skip to content

Commit cceefc2

Browse files
committed
remove error db log
1 parent 628774c commit cceefc2

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

internal/infrastructure/permission/management.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,20 +44,21 @@ func Upsert(ctx context.Context, grant Grant) error {
4444
}
4545
fields := permissionGrantFieldSet(q)
4646

47-
existing, err := applyExactGrantFilter(q.PermissionGrant.WithContext(ctx).Unscoped(), fields, normalized).Take()
47+
res, err := applyExactGrantFilter(q.PermissionGrant.WithContext(ctx).Unscoped(), fields, normalized).Find()
48+
4849
switch {
49-
case err == nil:
50+
case len(res) > 0 && err == nil:
5051
updates := map[string]any{
5152
"remark": normalized.Remark,
5253
"updated_at": time.Now(),
5354
"deleted_at": nil,
5455
}
5556
_, err = q.PermissionGrant.WithContext(ctx).Unscoped().
56-
Where(fields.ID.Eq(existing.ID)).
57+
Where(fields.ID.Eq(res[0].ID)).
5758
Updates(updates)
5859
otel.RecordError(span, err)
5960
return err
60-
case errors.Is(err, gorm.ErrRecordNotFound):
61+
case len(res) == 0 || errors.Is(err, gorm.ErrRecordNotFound):
6162
err = q.PermissionGrant.WithContext(ctx).Create(toPermissionGrantModel(normalized))
6263
otel.RecordError(span, err)
6364
return err

0 commit comments

Comments
 (0)