From b10b1919a2df4d50b41ee40a01b0e4638851a2db Mon Sep 17 00:00:00 2001 From: Immanuel Onyeka Date: Mon, 4 Dec 2023 22:15:16 -0500 Subject: [PATCH] Download PDFs from estimate view --- components/app.vue | 14 +++++++++++++- components/download-dialog.vue | 27 +++++++++++++++++++++++++++ components/estimates.vue | 31 ++++++++++++++++++++++++++++++- skouter.go | 9 ++++++--- 4 files changed, 76 insertions(+), 5 deletions(-) create mode 100644 components/download-dialog.vue diff --git a/components/app.vue b/components/app.vue index ba6a806..3a028ba 100644 --- a/components/app.vue +++ b/components/app.vue @@ -225,7 +225,19 @@ function start() { } function downloadEstimate(estimate) { - + fetch(`/api/pdf`, + {method: 'POST', + body: JSON.stringify(estimate), + headers: { + "Accept": "application/json", + "Authorization": `Bearer ${this.token}`, + }, + }).then(response => { + if (response.ok) { return response.blob() } + }).then (result => { + console.log(result) + if (!result) return // Exit if token is invalid or blank file returned + }) } export default { diff --git a/components/download-dialog.vue b/components/download-dialog.vue new file mode 100644 index 0000000..eb7d236 --- /dev/null +++ b/components/download-dialog.vue @@ -0,0 +1,27 @@ + + + + + diff --git a/components/estimates.vue b/components/estimates.vue index cbd1730..72d830b 100644 --- a/components/estimates.vue +++ b/components/estimates.vue @@ -54,18 +54,23 @@ ${{(estimate.price / 100).toLocaleString()}} - + + + + + + diff --git a/skouter.go b/skouter.go index dd75eff..ebbefd9 100644 --- a/skouter.go +++ b/skouter.go @@ -2268,7 +2268,10 @@ func clipLetterhead(w http.ResponseWriter, db *sql.DB, r *http.Request) { // claims, err := getClaims(r) if err != nil { http.Error(w, "Invalid token.", 422); return } img, t, err := image.Decode(r.Body) - if err != nil { http.Error(w, "Invalid file.", 422); return } + if err != nil { + http.Error(w, "Invalid file, JPEG and PNG only.", 422) + return + } for _, v := range validTypes { if v == "image/"+t { isValidType = true } } @@ -2646,8 +2649,8 @@ func seedEstimates(db *sql.DB, users []User, ltypes []LoanType) []Estimate { estimates = append(estimates, estimate) } - estimate[0].User = users[0].Id - estimate[1].User = users[0].Id + estimates[0].User = users[0].Id + estimates[1].User = users[0].Id for i := range estimates { err = estimates[i].insertEstimate(db)