Browse Source

Add deleteFeeTemp endpoint to delete fees

master
Immanuel Onyeka 1 year ago
parent
commit
da111e4c06
3 changed files with 40 additions and 6 deletions
  1. +5
    -1
      components/app.vue
  2. +15
    -5
      components/estimates.vue
  3. +20
    -0
      skouter.go

+ 5
- 1
components/app.vue View File

@@ -16,12 +16,16 @@
:fees="fees"
:token="token"
v-else-if="active == 2" />

<estimates
:user="user"
:fees="fees"
v-else-if="active == 3"
:token="token"
@addFeeTemp="(f) => fees.push(f)" />
@addFeeTemp="(f) => fees.push(f)"
@removeFeeTemp="(fee) => fees = fees.filter(f => f.id != fee.id)"
/>

<settings :user="user" v-else-if="active == 4" />
<sign-out :user="user" v-else-if="active == 5" />
</template>


+ 15
- 5
components/estimates.vue View File

@@ -14,7 +14,7 @@
{{fee.type}}
</label>
<img width="21" height="21" src="/assets/image/icon/x-red.svg"
@click="() => remove(indx, 1)">
@click="() => remove(fee)">
</div>
<button @click="() => edit = {}">New Fee</button>
</section>
@@ -71,7 +71,7 @@ import FeeDialog from "./fee-dialog.vue"
import { format } from "../helpers.js"

const props = defineProps(['user', 'fees', 'token'])
const emit = defineEmits(['addFeeTemp'])
const emit = defineEmits(['addFeeTemp', 'removeFeeTemp'])
let edit = ref(null)
let estimates = ref([])
let estimate = ref()
@@ -105,8 +105,19 @@ function newType() {

}

function remove() {

function remove(fee) {
fetch(`/api/fee`,
{method: 'DELETE',
headers: {
"Accept": "application/json",
"Authorization": `Bearer ${props.token}`,
},
body: JSON.stringify(fee)
}).then(response => {
if (response.ok) { emit('removeFeeTemp', fee) } else {
response.text().then(t => console.log(t))
}
})
}

function getEstimates() {
@@ -125,7 +136,6 @@ function getEstimates() {
estimates.value = result
// console.log(result)
})

}

function summarize() {


+ 20
- 0
skouter.go View File

@@ -442,6 +442,22 @@ func createFeesTemp(w http.ResponseWriter, db *sql.DB, r *http.Request) {
json.NewEncoder(w).Encode(fee)
}

// Fetch fees from the database
func deleteFeeTemp(w http.ResponseWriter, db *sql.DB, r *http.Request) {
var fee FeeTemplate
var query string
var err error
// claims, err := getClaims(r)
// var id int // Inserted estimate's id
err = json.NewDecoder(r.Body).Decode(&fee)
if err != nil { w.WriteHeader(422); return }

query = `DELETE FROM fee_template WHERE id = ?`
_, err = db.Exec(query, fee.Id)
if err != nil { w.WriteHeader(500); return }
}

func getMi(db *sql.DB, loan int) (MI, error) {
var mi MI

@@ -1551,6 +1567,10 @@ func api(w http.ResponseWriter, r *http.Request) {
r.Method == http.MethodPost &&
guard(r, 1):
createFeesTemp(w, db, r)
case match(p, "/api/fee", &args) &&
r.Method == http.MethodDelete &&
guard(r, 1):
deleteFeeTemp(w, db, r)
case match(p, "/api/estimates", &args) &&
r.Method == http.MethodGet &&
guard(r, 1):


Loading…
Cancel
Save