feat(account): get a specific account
This commit is contained in:
@@ -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}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user