feat(accounts): improve account creation
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
package account
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"nos-comptes/internal/storage/dao"
|
||||
"nos-comptes/internal/storage/dao/postgresql"
|
||||
"nos-comptes/internal/utils"
|
||||
|
||||
"github.com/lib/pq"
|
||||
)
|
||||
@@ -41,13 +44,22 @@ func (db *Database) GetAccountWithNameForUser(name string, id string) (*Account,
|
||||
WHERE a.user_id = $1
|
||||
AND a.name = $2
|
||||
`
|
||||
row := db.Session.QueryRow(q, id, name)
|
||||
|
||||
row, err := db.Session.Query(q, id, name)
|
||||
if !row.Next() {
|
||||
return nil, dao.NewDAOError(dao.ErrTypeNotFound, fmt.Errorf("No row found"))
|
||||
}
|
||||
a := Account{}
|
||||
err := row.Scan(&a.ID, &a.UserId, &a.Name, &a.Provider, &a.CreatedAt, &a.UpdatedAt)
|
||||
row.Scan(&a.ID, &a.UserId, &a.Name, &a.Provider, &a.CreatedAt, &a.UpdatedAt)
|
||||
if row.Next() {
|
||||
return nil, fmt.Errorf("Impossibru")
|
||||
}
|
||||
if errPq, ok := err.(*pq.Error); ok {
|
||||
return nil, postgresql.HandlePgError(errPq)
|
||||
}
|
||||
if err != nil {
|
||||
utils.GetLogger().Info(err)
|
||||
return nil, err
|
||||
}
|
||||
return &a, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user