Skip to content
This repository has been archived by the owner on Dec 9, 2021. It is now read-only.

Commit

Permalink
Merge pull request moov-io#549 from adamdecaf/nil-returnCode
Browse files Browse the repository at this point in the history
api,client: marshal null returnCode, not zero-value model
  • Loading branch information
adamdecaf authored Aug 14, 2020
2 parents c2aeb50 + 76aa2ef commit a971fa8
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 25 deletions.
3 changes: 1 addition & 2 deletions api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -673,8 +673,6 @@ components:
$ref: '#/components/schemas/Amount'
status:
$ref: '#/components/schemas/TransferStatus'
returnCode:
$ref: '#/components/schemas/ReturnCode'
processedAt:
type: string
format: date-time
Expand Down Expand Up @@ -822,6 +820,7 @@ components:
type: string
description: Long form explanation of return code
example: Previously active account has been closed by customer or RDFI
nullable: true
required:
- code
- reason
Expand Down
1 change: 0 additions & 1 deletion pkg/client/docs/MicroDeposits.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ Name | Type | Description | Notes
**Destination** | [**Destination**](Destination.md) | |
**Amounts** | **[]string** | |
**Status** | [**TransferStatus**](TransferStatus.md) | |
**ReturnCode** | [**ReturnCode**](ReturnCode.md) | | [optional]
**ProcessedAt** | Pointer to [**time.Time**](time.Time.md) | | [optional]
**Created** | [**time.Time**](time.Time.md) | |

Expand Down
2 changes: 1 addition & 1 deletion pkg/client/docs/Transfer.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Name | Type | Description | Notes
**Description** | **string** | Brief description of the transaction, that may appear on the receiving entity’s financial statement. This field is put into the Entry Detail's DiscretionaryData. |
**Status** | [**TransferStatus**](TransferStatus.md) | |
**SameDay** | **bool** | When set to true this indicates the transfer should be processed the same day if possible. | [default to false]
**ReturnCode** | [**ReturnCode**](ReturnCode.md) | | [optional]
**ReturnCode** | Pointer to [**ReturnCode**](ReturnCode.md) | | [optional]
**ProcessedAt** | Pointer to [**time.Time**](time.Time.md) | | [optional]
**Created** | [**time.Time**](time.Time.md) | |

Expand Down
1 change: 0 additions & 1 deletion pkg/client/model_micro_deposits.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ type MicroDeposits struct {
Destination Destination `json:"destination"`
Amounts []string `json:"amounts"`
Status TransferStatus `json:"status"`
ReturnCode ReturnCode `json:"returnCode,omitempty"`
ProcessedAt *time.Time `json:"processedAt,omitempty"`
Created time.Time `json:"created"`
}
8 changes: 4 additions & 4 deletions pkg/client/model_transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ type Transfer struct {
Description string `json:"description"`
Status TransferStatus `json:"status"`
// When set to true this indicates the transfer should be processed the same day if possible.
SameDay bool `json:"sameDay"`
ReturnCode ReturnCode `json:"returnCode,omitempty"`
ProcessedAt *time.Time `json:"processedAt,omitempty"`
Created time.Time `json:"created"`
SameDay bool `json:"sameDay"`
ReturnCode *ReturnCode `json:"returnCode,omitempty"`
ProcessedAt *time.Time `json:"processedAt,omitempty"`
Created time.Time `json:"created"`
}
4 changes: 4 additions & 0 deletions pkg/database/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ var (
"add_processed_at__to__micro_deposits",
`alter table micro_deposits add column processed_at datetime;`,
),
execsql(
"drop_micro_deposit_return_code",
"alter table micro_deposits drop column return_code;",
),
)
)

Expand Down
2 changes: 1 addition & 1 deletion pkg/transfers/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ limit 1`
}
if returnCode != nil {
if rc := ach.LookupReturnCode(*returnCode); rc != nil {
transfer.ReturnCode = client.ReturnCode{
transfer.ReturnCode = &client.ReturnCode{
Code: rc.Code,
Reason: rc.Reason,
Description: rc.Description,
Expand Down
17 changes: 2 additions & 15 deletions pkg/validation/microdeposits/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"database/sql"
"strings"

"github.com/moov-io/ach"
"github.com/moov-io/paygate/pkg/client"
)

Expand Down Expand Up @@ -36,7 +35,7 @@ func (r *sqlRepo) Close() error {
}

func (r *sqlRepo) getMicroDeposits(microDepositID string) (*client.MicroDeposits, error) {
query := `select micro_deposit_id, destination_customer_id, destination_account_id, amounts, status, return_code, processed_at, created_at from micro_deposits
query := `select micro_deposit_id, destination_customer_id, destination_account_id, amounts, status, processed_at, created_at from micro_deposits
where micro_deposit_id = ? and deleted_at is null limit 1;`
stmt, err := r.db.Prepare(query)
if err != nil {
Expand All @@ -47,7 +46,6 @@ where micro_deposit_id = ? and deleted_at is null limit 1;`
row := stmt.QueryRow(microDepositID)

var amounts string
var returnCode *string

var micro client.MicroDeposits
if err := row.Scan(
Expand All @@ -56,23 +54,13 @@ where micro_deposit_id = ? and deleted_at is null limit 1;`
&micro.Destination.AccountID,
&amounts,
&micro.Status,
&returnCode,
&micro.ProcessedAt,
&micro.Created,
); err != nil {
return nil, err
}

micro.Amounts = strings.Split(amounts, "|")
if returnCode != nil {
if rc := ach.LookupReturnCode(*returnCode); rc != nil {
micro.ReturnCode = client.ReturnCode{
Code: rc.Code,
Reason: rc.Reason,
Description: rc.Description,
}
}
}

micro.TransferIDs, err = r.getMicroDepositTransferIDs(microDepositID)
if err != nil {
Expand Down Expand Up @@ -128,7 +116,7 @@ func (r *sqlRepo) writeMicroDeposits(micro *client.MicroDeposits) error {
return err
}

query := `insert into micro_deposits (micro_deposit_id, destination_customer_id, destination_account_id, amounts, status, return_code, created_at) values (?, ?, ?, ?, ?, ?, ?);`
query := `insert into micro_deposits (micro_deposit_id, destination_customer_id, destination_account_id, amounts, status, created_at) values (?, ?, ?, ?, ?, ?);`
stmt, err := tx.Prepare(query)
if err != nil {
tx.Rollback()
Expand All @@ -142,7 +130,6 @@ func (r *sqlRepo) writeMicroDeposits(micro *client.MicroDeposits) error {
micro.Destination.AccountID,
strings.Join(micro.Amounts, "|"),
micro.Status,
micro.ReturnCode.Code,
micro.Created,
)
if err != nil {
Expand Down

0 comments on commit a971fa8

Please sign in to comment.