df/bff/db/sqlc/tx_update_account.go
2023-10-02 09:59:45 +02:00

48 lines
1.2 KiB
Go

package db
import (
"context"
"database/sql"
"github.com/itsscb/df/bff/util"
)
type UpdateAccountTxParams struct {
ID int64 `json:"ID"`
Changer string `json:"changer"`
Passwordhash sql.NullString `json:"passwordhash"`
Firstname sql.NullString `json:"firstname"`
Lastname sql.NullString `json:"lastname"`
Birthday sql.NullTime `json:"birthday"`
Email sql.NullString `json:"email"`
Phone sql.NullString `json:"phone"`
City sql.NullString `json:"city"`
Zip sql.NullString `json:"zip"`
Street sql.NullString `json:"street"`
Country sql.NullString `json:"country"`
}
type UpdateAccountTxResult struct {
Account Account `json:"account"`
}
func (store *SQLStore) UpdateAccountTx(ctx context.Context, arg UpdateAccountTxParams) (Account, error) {
var result UpdateAccountTxResult
var err error
if arg.Passwordhash.Valid {
arg.Passwordhash.String, err = util.HashPassword(arg.Passwordhash.String)
if err != nil {
return Account{}, nil
}
}
err = store.execTx(ctx, func(q *Queries) error {
var err error
result.Account, err = q.UpdateAccount(ctx, UpdateAccountParams(arg))
return err
})
return result.Account, err
}