more db refactors
This commit is contained in:
@@ -30,8 +30,7 @@ func AssignRole(ctx context.Context, tx bun.Tx, userID, roleID int) error {
|
||||
RoleID: roleID,
|
||||
}
|
||||
err := Insert(tx, userRole).
|
||||
On("CONFLICT (user_id, role_id) DO NOTHING").
|
||||
Exec(ctx)
|
||||
ConflictNothing("user_id", "role_id").Exec(ctx)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "db.Insert")
|
||||
}
|
||||
@@ -48,11 +47,10 @@ func RevokeRole(ctx context.Context, tx bun.Tx, userID, roleID int) error {
|
||||
return errors.New("roleID must be positive")
|
||||
}
|
||||
|
||||
_, err := tx.NewDelete().
|
||||
Model((*UserRole)(nil)).
|
||||
err := DeleteItem[UserRole](tx).
|
||||
Where("user_id = ?", userID).
|
||||
Where("role_id = ?", roleID).
|
||||
Exec(ctx)
|
||||
Delete(ctx)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "tx.NewDelete")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user