Просмотр исходного кода

Bug fix: Transactions were not properly deleting.

Lee Morgan 11 месяцев назад
Родитель
Сommit
d1aa3a2900
2 измененных файлов с 5 добавлено и 7 удалено
  1. 3 5
      src/views/js/data/Transaction.js
  2. 2 2
      src/views/js/pages/TransactionDetails.js

+ 3 - 5
src/views/js/data/Transaction.js

@@ -68,9 +68,6 @@ export default class Transaction{
     }
     }
 
 
     static async fetch(account, from, to){
     static async fetch(account, from, to){
-        console.log(account);
-        console.log(from);
-        console.log(to);
         let response;
         let response;
         try{
         try{
             response = await fetch("/api/transaction/search", {
             response = await fetch("/api/transaction/search", {
@@ -79,7 +76,6 @@ export default class Transaction{
                 body: JSON.stringify({account, from, to})
                 body: JSON.stringify({account, from, to})
             });
             });
             response = await response.json();
             response = await response.json();
-            console.log(response);
 
 
             const promises = [];
             const promises = [];
             for(let i = 0; i < response.length; i++){
             for(let i = 0; i < response.length; i++){
@@ -121,13 +117,15 @@ export default class Transaction{
     }
     }
 
 
     async delete(){
     async delete(){
-        let response = await fetch(`/api/transactions/${this._id}`, {
+        let response = await fetch(`/api/transaction/${this._id}`, {
             method: "DELETE",
             method: "DELETE",
             headers: {"Content-Type": "application/json"}
             headers: {"Content-Type": "application/json"}
         });
         });
         response = await response.json(); 
         response = await response.json(); 
 
 
         if(response.error) throw response.error;
         if(response.error) throw response.error;
+
+        this._parent.removeTransaction(this);
     }
     }
 
 
     async save(isNew = false){
     async save(isNew = false){

+ 2 - 2
src/views/js/pages/TransactionDetails.js

@@ -1,6 +1,7 @@
 import Page from "./Page.js";
 import Page from "./Page.js";
 import Elem from "../Elem.js";
 import Elem from "../Elem.js";
 import Format from "../Format.js";
 import Format from "../Format.js";
+import Notifier from "../Notifier.js";
 
 
 export default class TransactionDetails extends Page{
 export default class TransactionDetails extends Page{
     constructor(transaction){
     constructor(transaction){
@@ -37,8 +38,7 @@ export default class TransactionDetails extends Page{
 
 
     async delete(transaction){
     async delete(transaction){
         try{
         try{
-            const response = await transaction.delete();
-            if(response.error) throw response.error;
+            await transaction.delete();
         }catch(e){
         }catch(e){
             if(e.error){
             if(e.error){
                 new Notifier("error", e.error.message);
                 new Notifier("error", e.error.message);