@@ -16,12 +16,16 @@ | |||||
:fees="fees" | :fees="fees" | ||||
:token="token" | :token="token" | ||||
v-else-if="active == 2" /> | v-else-if="active == 2" /> | ||||
<estimates | <estimates | ||||
:user="user" | :user="user" | ||||
:fees="fees" | :fees="fees" | ||||
v-else-if="active == 3" | v-else-if="active == 3" | ||||
:token="token" | :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" /> | <settings :user="user" v-else-if="active == 4" /> | ||||
<sign-out :user="user" v-else-if="active == 5" /> | <sign-out :user="user" v-else-if="active == 5" /> | ||||
</template> | </template> | ||||
@@ -14,7 +14,7 @@ | |||||
{{fee.type}} | {{fee.type}} | ||||
</label> | </label> | ||||
<img width="21" height="21" src="/assets/image/icon/x-red.svg" | <img width="21" height="21" src="/assets/image/icon/x-red.svg" | ||||
@click="() => remove(indx, 1)"> | |||||
@click="() => remove(fee)"> | |||||
</div> | </div> | ||||
<button @click="() => edit = {}">New Fee</button> | <button @click="() => edit = {}">New Fee</button> | ||||
</section> | </section> | ||||
@@ -71,7 +71,7 @@ import FeeDialog from "./fee-dialog.vue" | |||||
import { format } from "../helpers.js" | import { format } from "../helpers.js" | ||||
const props = defineProps(['user', 'fees', 'token']) | const props = defineProps(['user', 'fees', 'token']) | ||||
const emit = defineEmits(['addFeeTemp']) | |||||
const emit = defineEmits(['addFeeTemp', 'removeFeeTemp']) | |||||
let edit = ref(null) | let edit = ref(null) | ||||
let estimates = ref([]) | let estimates = ref([]) | ||||
let estimate = 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() { | function getEstimates() { | ||||
@@ -125,7 +136,6 @@ function getEstimates() { | |||||
estimates.value = result | estimates.value = result | ||||
// console.log(result) | // console.log(result) | ||||
}) | }) | ||||
} | } | ||||
function summarize() { | function summarize() { | ||||
@@ -442,6 +442,22 @@ func createFeesTemp(w http.ResponseWriter, db *sql.DB, r *http.Request) { | |||||
json.NewEncoder(w).Encode(fee) | 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) { | func getMi(db *sql.DB, loan int) (MI, error) { | ||||
var mi MI | var mi MI | ||||
@@ -1551,6 +1567,10 @@ func api(w http.ResponseWriter, r *http.Request) { | |||||
r.Method == http.MethodPost && | r.Method == http.MethodPost && | ||||
guard(r, 1): | guard(r, 1): | ||||
createFeesTemp(w, db, r) | 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) && | case match(p, "/api/estimates", &args) && | ||||
r.Method == http.MethodGet && | r.Method == http.MethodGet && | ||||
guard(r, 1): | guard(r, 1): | ||||