fixed db issues

This commit is contained in:
2026-02-05 20:07:37 +11:00
parent 59ee880b63
commit 2e2c2af44d
9 changed files with 140 additions and 61 deletions

View File

@@ -2,6 +2,7 @@ package db
import (
"context"
"database/sql"
"git.haelnorr.com/h/oslstats/internal/roles"
"github.com/pkg/errors"
@@ -72,9 +73,12 @@ func HasRole(ctx context.Context, tx bun.Tx, userID int, roleName roles.Role) (b
err := tx.NewSelect().
Model(user).
Relation("Roles").
Where("u.id = ? ", userID).
Where("u.id = ?", userID).
Scan(ctx)
if err != nil {
if err == sql.ErrNoRows {
return false, nil
}
return false, errors.Wrap(err, "tx.NewSelect")
}
for _, role := range user.Roles {