perf(db): remove extra checks from roles funcs

This commit is contained in:
Masahiko AMANO 2025-01-18 19:34:03 +03:00
parent 33e2aee9f5
commit cce32210ef

View File

@ -112,7 +112,7 @@ func RoleGet(ctx context.Context, user_id, person_id string) (role models.Role,
return
}
pgErr := err.(*pgconn.PgError)
if pgErr.Code == "22P02" || pgErr.Code == "22007" {
if pgErr.Code == "22P02" {
err = fmt.Errorf("%s", pgErr.Message)
statusCode = http.StatusBadRequest
} else {
@ -140,7 +140,7 @@ func RoleAdd(ctx context.Context, user_id, name string) (role models.Role, statu
err = row.Scan(&role.ID, &role.Name)
if err != nil {
pgErr := err.(*pgconn.PgError)
if pgErr.Code == "22P02" || pgErr.Code == "22007" {
if pgErr.Code == "22P02" {
err = fmt.Errorf("%s", pgErr.Message)
statusCode = http.StatusBadRequest
} else if pgErr.Code == "23505" {
@ -177,7 +177,7 @@ func RoleUpdate(ctx context.Context, user_id, role_id string, values map[string]
commandTag, err = tx.Exec(ctx, fmt.Sprintf("UPDATE roles SET %s=NULLIF($2, '') WHERE id=$1", field), role_id, value)
if err != nil {
pgErr := err.(*pgconn.PgError)
if pgErr.Code == "22P02" || pgErr.Code == "22007" {
if pgErr.Code == "22P02" {
err = fmt.Errorf("%s", pgErr.Message)
statusCode = http.StatusBadRequest
} else if pgErr.Code == "23505" {