Skip to content
This repository has been archived by the owner on Feb 4, 2025. It is now read-only.

Commit

Permalink
Prevent delete payee,wallet, category if there is transactions attach…
Browse files Browse the repository at this point in the history
… to them
  • Loading branch information
GrPe committed Jun 4, 2024
1 parent 8966d6e commit b4f411e
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<form @submit.prevent="updateCategory">
<input type="text" v-model="categoryName" required/>
<button type="submit">Update</button>
<input type="button" class="delete" value="Delete" @click="removeCategory()"/>
<input type="button" class="delete" value="Delete" @click="removeCategory()" :disabled="disableRemove"/>
</form>
</article>
</dialog>
Expand All @@ -20,6 +20,7 @@ import type { PropType } from 'vue';
export default {
props: {
show: Boolean,
disableRemove: Boolean,
currentValue: {
type: Object as PropType<Category>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<form @submit.prevent="updatePayee">
<input type="text" v-model="payeeName" required/>
<button type="submit">Update</button>
<input type="button" class="delete" value="Delete" @click="removePayee()"/>
<input type="button" class="delete" value="Delete" @click="removePayee()" :disabled="disableRemove"/>
</form>
</article>
</dialog>
Expand All @@ -21,6 +21,7 @@ import type { PropType } from 'vue';
export default {
props: {
show: Boolean,
disableRemove: Boolean,
currentValue: {
type: Object as PropType<Payee>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
Update Wallet
</header>
<form @submit.prevent="updateWallet">
<input type="text" v-model="walletName" required/>
<input type="text" v-model="walletName" required />

<label for="currency">Currency</label>
<select v-model="currencyId" id="currency" required>
Expand All @@ -16,7 +16,7 @@
</select>

<button type="submit">Update</button>
<input type="button" class="delete" value="Delete" @click="removeWallet()"/>
<input type="button" class="delete" value="Delete" @click="removeWallet()" :disabled="disableRemove"/>
</form>
</article>
</dialog>
Expand All @@ -29,6 +29,7 @@ import type { PropType } from 'vue';
export default {
props: {
show: Boolean,
disableRemove: Boolean,
currencies: Array<Currency>,
currentValue: {
type: Object as PropType<Wallet>
Expand Down
11 changes: 10 additions & 1 deletion src/Overmoney.Portal/src/components/views/CategoryView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</CategoryList>
<CreateCategoryModal :show="showModal" @created="onCreateCategory" @cancel="showModal = false" />
<UpdateCategoryModal :show="showUpdateModal" @updated="updateCategory" :currentValue="categoryToUpdate"
@cancel="showUpdateModal = false" @removeCategory="onRemoveCategory" />
@cancel="showUpdateModal = false" @removeCategory="onRemoveCategory" :disableRemove="disableRemove"/>
</template>

<script lang="ts">
Expand All @@ -31,6 +31,7 @@ export default {
categories: [] as Array<Category>,
showModal: false,
showUpdateModal: false,
disableRemove: false,
categoryToUpdate: {} as Category | undefined,
session
}
Expand All @@ -55,6 +56,14 @@ export default {
await this.client.removeCategory(id);
},
async onUpdateCategory(id: number) {
let transactions = await this.client.getTransactionsByCategory(this.session.userId, id);
if(transactions != null && transactions.length > 0) {
this.disableRemove = true;
} else {
this.disableRemove = false;
}
let category = this.categories.find(x => x.id == id);
this.categoryToUpdate = category;
this.showUpdateModal = true;
Expand Down
11 changes: 10 additions & 1 deletion src/Overmoney.Portal/src/components/views/PayeeView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</PayeesList>
<CreatePayeeModal :show="showModal" @created="onCreatePayee" @cancel="showModal = false" />
<UpdatePayeeModal :show="showUpdateModal" @updated="updatePayee" :currentValue="payeeToUpdate"
@cancel="showUpdateModal = false" @removePayee="onRemovePayee" />
@cancel="showUpdateModal = false" @removePayee="onRemovePayee" :disableRemove="disableRemove" />
</template>

<script lang="ts">
Expand All @@ -31,6 +31,7 @@ export default {
payees: [] as Array<Payee>,
showModal: false,
showUpdateModal: false,
disableRemove: false,
payeeToUpdate: {} as Payee | undefined,
session
}
Expand All @@ -55,6 +56,14 @@ export default {
await this.client.removePayee(id);
},
async onUpdatePayee(id: number) {
let transactions = await this.client.getTransactionsByPayee(this.session.userId, id);
if (transactions != null && transactions.length > 0) {
this.disableRemove = true;
} else {
this.disableRemove = false;
}
let payee = this.payees.find(x => x.id == id);
this.payeeToUpdate = payee;
this.showUpdateModal = true;
Expand Down
13 changes: 12 additions & 1 deletion src/Overmoney.Portal/src/components/views/WalletView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<CreateWalletModal :show="showModal" :currencies="currencies" @created="onCreateWallet"
@cancel="showModal = false" />
<UpdateWalletModal :show="showUpdateModal" :currencies="currencies" @updated="updateWallet"
:currentValue="walletToUpdate" @cancel="showUpdateModal = false" @removeWallet="onRemoveWallet" />
:currentValue="walletToUpdate" @cancel="showUpdateModal = false" @removeWallet="onRemoveWallet" :disableRemove="disableRemove" />
</template>

<script lang="ts">
Expand All @@ -34,6 +34,7 @@ export default {
currencies: [] as Array<Currency>,
showModal: false,
showUpdateModal: false,
disableRemove: false,
walletToUpdate: {} as Wallet | undefined,
session
}
Expand All @@ -60,6 +61,16 @@ export default {
await this.client.removeWallet(id);
},
async onUpdateWallet(id: number) {
let transactions = await this.client.getTransactionsByWallet(this.session.userId, id);
console.log(transactions);
if (transactions != null && transactions != undefined && transactions.length > 0) {
this.disableRemove = true;
} else {
this.disableRemove = false;
}
let wallet = this.wallets.find(x => x.id == id);
this.walletToUpdate = wallet;
this.showUpdateModal = true;
Expand Down
39 changes: 39 additions & 0 deletions src/Overmoney.Portal/src/data_access/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,45 @@ export class Client {
return response.data;
}

async getTransactionsByWallet(userId: number, walletId: number): Promise<Transaction[] | null> {
const response = await axios.get<Array<Transaction>>(
import.meta.env.VITE_API_URL +
`users/${userId}/transactions?walletId=${walletId}`
);

if (response == null) {
return null;
}

return response.data;
}

async getTransactionsByCategory(userId: number, categoryId: number): Promise<Transaction[] | null> {
const response = await axios.get<Array<Transaction>>(
import.meta.env.VITE_API_URL +
`users/${userId}/transactions?categoryId=${categoryId}`
);

if (response == null) {
return null;
}

return response.data;
}

async getTransactionsByPayee(userId: number, payeeId: number): Promise<Transaction[] | null> {
const response = await axios.get<Array<Transaction>>(
import.meta.env.VITE_API_URL +
`users/${userId}/transactions?payeeId=${payeeId}`
);

if (response == null) {
return null;
}

return response.data;
}

async createTransaction(
request: createTransactionRequest
): Promise<Transaction> {
Expand Down
4 changes: 4 additions & 0 deletions src/Overmoney.Portal/src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ axios.interceptors.response.use(null, (error) => {
router.push("/login");
}

if (error.response.status == 404) {
return Promise.resolve(null);
}

return Promise.reject(error);
});

Expand Down

0 comments on commit b4f411e

Please sign in to comment.