diff --git a/components/new/details.vue b/components/new/details.vue
index 5d8062c..760da35 100644
--- a/components/new/details.vue
+++ b/components/new/details.vue
@@ -66,26 +66,26 @@
name="loan_type"
:checked="loan.type.id == 1"
value="1"
- @change="(e) => $emit('update:loanType', e.target.value)"
+ @change="(e) => $emit('update:loanType', 1)"
>
$emit('update:loanType', e.target.value)">
+ @change="(e) => $emit('update:loanType', 2)">
$emit('update:loanType', e.target.value)">
+ @change="(e) => $emit('update:loanType', 3)">
$emit('update:loanType', e.target.value)">
+ @change="(e) => $emit('update:loanType', 4)">
@@ -105,7 +105,7 @@
$emit('update:ltv', e)">
- $emit('update:amount', e)">
estimate.property = p"
- @update:loanType="(lt) => loans[sel].type = lt"
+ @update:loanType="(lt) => loan.type.id = lt"
@update:term="(lt) => loans[sel].term = lt"
@update:program="(p) => loans[sel].program = p"
@update:ltv="setLtv"
@@ -56,7 +56,7 @@ class="bi bi-plus" viewBox="0 0 16 16">
+ :loan="loan" :downpayment="estimate.price - loan.amount" :token="token" :estimate="estimate"/>
@@ -66,10 +66,10 @@ import { stripLetters, strip, stripInt, stripPerc } from "../../helpers.js"
import LoanDetails from "./details.vue"
import LoanSummary from "./summary.vue"
-// The default values of a new estimate
+// The default values of a new loan
const example = {
title: "Example",
- type: "",
+ type: {},
term: 0,
ltv: 0, // Loan to home value ratio
dti: 0,
@@ -91,11 +91,7 @@ const example = {
// The default loans on a new estimate
const loans = [
- Object.assign({}, example,),
- Object.assign(
- Object.assign({}, example),
- {title: "Another One", mi: {rate: 0}, type: {}}
- ),
+ Object.assign({mi: { monthly: false, rate: 0 }, type: {}}, example)
]
// Default estimate fields
@@ -115,7 +111,7 @@ function loan() {
function create() {
this.estimate.loans.push(
Object.assign(
- {},
+ {mi: { monthly: false, rate: 0 }, type: {}},
example, {fees: this.createFees()}
)
)
@@ -155,10 +151,11 @@ function setLtv(e) {
this.loan.ltv = ltv
let num = ltv / 100 * this.estimate.price
- this.loan.amount = Math.round(num*100) / 100
+ this.loan.amount = Math.round(num*100)
}
// Changes loan.amount\'s and data() values, then syncs with data.ltv
+// Loan amount is in cents but LTV is in decimals so some rounding needs to be done.
function setAmount(e) {
let amount = strip(e)
if (!this.estimate.price) return
@@ -166,7 +163,7 @@ function setAmount(e) {
if (amount > this.loan.price) amount = this.loan.price
if (amount < 0) amount = 0
- this.loan.amount = amount
+ this.loan.amount = Math.round(amount * 100)
let num = amount / this.estimate.price * 100
this.loan.ltv = Math.round(num*100) / 100
}
diff --git a/components/new/summary.vue b/components/new/summary.vue
index adbdb3a..83e3db7 100644
--- a/components/new/summary.vue
+++ b/components/new/summary.vue
@@ -29,8 +29,8 @@
diff --git a/skouter.go b/skouter.go
index ed1f031..a2f76c0 100644
--- a/skouter.go
+++ b/skouter.go
@@ -87,7 +87,7 @@ type LoanType struct {
type Loan struct {
Id int `json:id`
EstimateId int `json:estimate_id`
- Type LoanType `json:"loanType"`
+ Type LoanType `json:"type"`
Amount int `json:"amount"`
Amortization string `json:"amortization"`
Term int `json:"term"`
@@ -954,15 +954,17 @@ func checkEstimate(e Estimate) error {
// Can be used to check rules for specific loan types
var err error
- switch l.Type.Name {
- case "Conventional":
+ switch l.Type.Id {
+ case 1:
err = checkConventional(l, e.Borrower)
- case "FHA":
+ case 2:
err = checkFHA(l, e.Borrower)
- case "VA":
+ case 3:
err = checkConventional(l, e.Borrower)
- case "USDA":
+ case 4:
err = checkConventional(l, e.Borrower)
+ default:
+ err = errors.New("Invalid loan type")
}
if err != nil { return err }
@@ -976,7 +978,7 @@ func validateEstimate(w http.ResponseWriter, db *sql.DB, r *http.Request) {
var estimate Estimate
err := json.NewDecoder(r.Body).Decode(&estimate)
- if err != nil { http.Error(w, "Invalid fields.", 422); return }
+ if err != nil { http.Error(w, err.Error(), 422); return }
err = checkEstimate(estimate)
if err != nil { http.Error(w, err.Error(), 406); return }
@@ -1041,6 +1043,8 @@ func api(w http.ResponseWriter, r *http.Request) {
r.Method == http.MethodPost &&
guard(r, 1):
validateEstimate(w, db, r)
+ default:
+ http.Error(w, "Invalid route or token", 404)
}
db.Close()