From 84d6807b94cb9db881acd5cdf1f270fdbbf43d20 Mon Sep 17 00:00:00 2001 From: Immanuel Onyeka Date: Wed, 21 Jun 2023 21:11:13 -0400 Subject: [PATCH] Create sample custom MI field --- components/new.vue | 28 ++++++++++++++++++++-------- skouter.go | 14 ++++++++++++++ 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/components/new.vue b/components/new.vue index dc4fc3a..45c1419 100644 --- a/components/new.vue +++ b/components/new.vue @@ -159,14 +159,13 @@ v-model="estimate.transaction">

Mortgage Insurance

- - - - + + + + +
@@ -207,6 +206,7 @@ const example = { pud: true, // Property under development zip: '', fees: [], + mi: 0 } // The default loans on a new estimate @@ -331,6 +331,18 @@ function setHousingDti(e) { function generate() { this.errors = this.validate() + if (this.errors.length) return + + fetch(`/api/estimate`, + { + method: 'POST', + body: JSON.stringify( this.estimate ), + headers: { + "Accept": "application/json", + "Authorization": `Bearer ${token}`, + }, + } + ) } function validate() { diff --git a/skouter.go b/skouter.go index a5688c6..82f3d6f 100644 --- a/skouter.go +++ b/skouter.go @@ -863,6 +863,16 @@ func createUser(w http.ResponseWriter, db *sql.DB, r *http.Request) { json.NewEncoder(w).Encode(user) } +func createEstimate(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, "Error creating user.", 422); return } + + json.NewEncoder(w).Encode(estimate) +} + func api(w http.ResponseWriter, r *http.Request) { var args []string @@ -914,6 +924,10 @@ func api(w http.ResponseWriter, r *http.Request) { r.Method == http.MethodGet && guard(r, 1): getFeesTemp(w, db, r) + case match(p, "/api/estimate", &args) && + r.Method == http.MethodPost && + guard(r, 1): + createEstimate(w, db, r) } db.Close()