feat(account): get a specific account

This commit is contained in:
2021-11-23 01:47:06 +01:00
parent e05bd1c743
commit 4035478c54
3 changed files with 91 additions and 4 deletions

View File

@@ -91,6 +91,26 @@ func (db *Database) DeleteAccountOfAnUser(userId, accountId string) error {
return err
}
func (db *Database) GetASpecificAccountForUser(userId, accountId string) (*Account, error) {
q := `
SELECT a.id, a.user_id, a.name, a.provider, a.created_at, a.updated_at
FROM public.account a
WHERE a.user_id = $1
AND a.id = $2
`
row := db.Session.QueryRow(q, userId, accountId)
a := Account{}
err := row.Scan(&a.ID, &a.UserId, &a.Name, &a.Provider, &a.CreatedAt, &a.UpdatedAt)
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
}
func NewDatabase(db *postgresql.DatabasePostgreSQL) *Database {
return &Database{db}
}