Skip to content

Commit

Permalink
Account removing support, rework config hash checking
Browse files Browse the repository at this point in the history
  • Loading branch information
isKONSTANTIN committed Jan 15, 2025
1 parent 7bb0466 commit ebf4176
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 6 deletions.
23 changes: 23 additions & 0 deletions components/accounts/entry.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

<div class="flex gap-1" v-if="!hideButtons">
<hide-button class="btn btn-xs btn-ghost m-0 p-0.5" :hide-status="account.hidden" @hide="hide" @unHide="unHide"/>
<delete-button v-if="account.hidden" class="btn btn-xs btn-ghost m-0 p-0.5" @event="deleteAccount" />
<edit-button v-if="!account.hidden" class="btn btn-xs btn-ghost m-0 p-0.5" @event="emit('edit-modal')"/>
</div>
</div>
Expand Down Expand Up @@ -59,6 +60,28 @@ const formatAmount = (delta) => {
return useCurrencyFormatter(delta, currency, locale.value);
}
const deleteAccount = () => {
$accountsApi.deleteAccount(props.account.accountId).then((r) => {
if (r.success)
$toastsManager.pushToast(t("accountEntry.messages.deleted"), 2500, "success")
else {
var messageType = "unknown";
if (r.errorMessage) {
if (r.errorMessage.startsWith("Some recurring")) {
messageType = "recurring";
}else if (r.errorMessage.startsWith("Some accumulation")) {
messageType = "accumulation";
}else if (r.errorMessage.startsWith("Some transactions")) {
messageType = "transactions";
}
}
$toastsManager.pushToast(t("accountEntry.messages.deleteFailCause." + messageType), 3000,"error")
}
})
}
const hide = () => {
$accountsApi.hideAccount(props.account.accountId).then((s) => {
if (s)
Expand Down
10 changes: 9 additions & 1 deletion lang/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,15 @@
"hided": "Account hidden",
"hideFail": "Failed to hide account",
"showed": "Account restored",
"showFail": "Failed to restore account"
"showFail": "Failed to restore account",

"deleted": "Account deleted",
"deleteFailCause": {
"recurring": "Account deletion failed because some recurring transaction affects to account",
"accumulation": "Account deletion failed because some accumulation settings affects to account",
"transactions": "Account deletion failed because some transactions affects to account",
"unknown": "Account deletion failed"
}
}
},

Expand Down
10 changes: 9 additions & 1 deletion lang/ru-RU.json
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,15 @@
"hided": "Счет скрыт",
"hideFail": "Ошибка при скрытии счета",
"showed": "Счет восстановлен",
"showFail": "Ошибка при восстановлении счета"
"showFail": "Ошибка при восстановлении счета",

"deleted": "Счет удален",
"deleteFailCause": {
"recurring": "Не удалось удалить счет, потому что какая-то повторяющаяся транзакция использует его",
"accumulation": "Не удалось удалить счет, потому что какие-то настройки автонакопления используют его",
"transactions": "Не удалось удалить счет, потому что существуют транзакции с его участием",
"unknown": "Не удалось удалить счет"
}
}
},

Expand Down
21 changes: 21 additions & 0 deletions libs/api/accounts/AccountsApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,27 @@ export class AccountsApi extends AbstractApi {
return true;
}

public async deleteAccount(accountId: number) : Promise<{success: boolean, errorMessage: string | null}> {
const opts = {
method: "POST",
params: { accountId: accountId }
};

const { data, error } = await useApi("/user/accounts/delete", opts);

if (error.value !== null) {
if (!data.value || !data.value.data)
return {success: false, errorMessage: null}

return {success: false, errorMessage: data.value.data.message};
}

this.accounts.value = this.accounts.value.filter((t) => t.accountId != accountId);
this.reloadMap();

return {success: true, errorMessage: null};
}

public async showAccount(accountId: number) {
const opts = {
method: "POST",
Expand Down
12 changes: 11 additions & 1 deletion libs/config/ConfigManager.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {ServerConfigs} from "~/libs/config/ServerConfigs";
import {useCookie} from "#app";
import {useStorage} from "@vueuse/core";
import {has} from "node-emoji";

export class ConfigManager {
private _configs : ServerConfigs | null = null;
Expand All @@ -10,8 +11,17 @@ export class ConfigManager {
async init(): Promise<void> {
const {data: hash, error} = await useApi<string>("configs/hash");

if (error.value !== null)
if (error.value !== null) {
console.warn("Failed to get config hash from server:", error.value)

return;
}

if (!hash.value || !hash.value.hash) {
console.warn("Invalid config hash from server:", hash.value)

return;
}

this._serverAvailable = true;

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "finwave",
"version": "1.4.3",
"version": "1.5.0",
"private": true,
"scripts": {
"build": "nuxt build",
Expand Down

0 comments on commit ebf4176

Please sign in to comment.