fixed db issues
This commit is contained in:
@@ -37,7 +37,10 @@ func GetPermissionByName(ctx context.Context, tx bun.Tx, name permissions.Permis
|
||||
Where("name = ?", name).
|
||||
Limit(1).
|
||||
Scan(ctx)
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, nil
|
||||
}
|
||||
return nil, errors.Wrap(err, "tx.NewSelect")
|
||||
}
|
||||
return perm, nil
|
||||
@@ -56,7 +59,10 @@ func GetPermissionByID(ctx context.Context, tx bun.Tx, id int) (*Permission, err
|
||||
Where("id = ?", id).
|
||||
Limit(1).
|
||||
Scan(ctx)
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, nil
|
||||
}
|
||||
return nil, errors.Wrap(err, "tx.NewSelect")
|
||||
}
|
||||
return perm, nil
|
||||
@@ -115,9 +121,22 @@ func CreatePermission(ctx context.Context, tx bun.Tx, perm *Permission) error {
|
||||
if perm == nil {
|
||||
return errors.New("permission cannot be nil")
|
||||
}
|
||||
if perm.Name == "" {
|
||||
return errors.New("name cannot be empty")
|
||||
}
|
||||
if perm.DisplayName == "" {
|
||||
return errors.New("display name cannot be empty")
|
||||
}
|
||||
if perm.Resource == "" {
|
||||
return errors.New("resource cannot be empty")
|
||||
}
|
||||
if perm.Action == "" {
|
||||
return errors.New("action cannot be empty")
|
||||
}
|
||||
|
||||
_, err := tx.NewInsert().
|
||||
Model(perm).
|
||||
Returning("id").
|
||||
Exec(ctx)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "tx.NewInsert")
|
||||
|
||||
Reference in New Issue
Block a user