Ver código fonte

Fix duplicate loan_id error

At most one result should exist for each loan stored but not redeclaring
the 'estimate' variable within the seed loop caused the loan entries of
the first estimate to be copied onto the second, which caused an error
while seeding result entries.
master
Immanuel Onyeka 1 ano atrás
pai
commit
274ea0581d
3 arquivos alterados com 46 adições e 1 exclusões
  1. +1
    -0
      components/estimates.vue
  2. +1
    -1
      migrations/0_29092022_setup_tables.sql
  3. +44
    -0
      skouter.go

+ 1
- 0
components/estimates.vue Ver arquivo

@@ -149,6 +149,7 @@ function summarize() {
response.text().then(t => console.log(t))
}
}).then(result => {
console.log(result)
if (!result || !result.length) return // Exit if token is invalid or no fees are saved
console.log('done', result)
})


+ 1
- 1
migrations/0_29092022_setup_tables.sql Ver arquivo

@@ -178,7 +178,7 @@ CREATE TABLE fee_template (

CREATE TABLE estimate_result (
id INT AUTO_INCREMENT,
loan_id INT NOT NULL,
loan_id INT UNIQUE NOT NULL,
loan_payment INT NOT NULL,
total_monthly INT NOT NULL,
total_fees INT NOT NULL,


+ 44
- 0
skouter.go Ver arquivo

@@ -1619,6 +1619,44 @@ func getResults(db *sql.DB, e int, id int) ( []Result, error ) {
return results, nil
}

// Retrieve an estimate result with a specified loan id
func getResult(db *sql.DB, loan int) ( Result, error ) {
var result Result
var query string
var err error

query = `SELECT
r.id,
loan_id,
loan_payment,
total_monthly,
total_fees,
total_credits,
cash_to_close
FROM estimate_result r
INNER JOIN loan
ON r.loan_id = loan.id
WHERE loan.Id = ?
`
row := db.QueryRow(query, loan)

err = row.Scan(
&result.Id,
&result.LoanId,
&result.LoanPayment,
&result.TotalMonthly,
&result.TotalFees,
&result.TotalCredits,
&result.CashToClose,
)

if err != nil {
return result, err
}

return result, nil
}

// Must have an estimate ID 'e', but not necessarily a loan id 'id'
func getLoans(db *sql.DB, e int, id int) ( []Loan, error ) {
var loans []Loan
@@ -1680,6 +1718,11 @@ func getLoans(db *sql.DB, e int, id int) ( []Loan, error ) {
}
loan.Fees = fees
loan.Result, err = getResult(db, loan.Id)
if err != nil {
return loans, err
}

loan.Type, err = getLoanType(db, loan.Type.Id)
if err != nil {
return loans, err
@@ -2571,6 +2614,7 @@ func seedEstimates(db *sql.DB, users []User, ltypes []LoanType) []Estimate {
var err error

for i := 0; i < 15; i++ {
estimate = Estimate{}
estimate.User = users[gofakeit.Number(0, len(users) - 1)].Id
estimate.Borrower = Borrower{
Credit: gofakeit.Number(600, 800),


Carregando…
Cancelar
Salvar