diff --git a/src/lib/category.ts b/src/lib/category.ts index 8ae5b5e2..6347a59f 100644 --- a/src/lib/category.ts +++ b/src/lib/category.ts @@ -2,17 +2,6 @@ import { CategoryType } from '@/core/category.ts'; import { TransactionType } from '@/core/transaction.ts'; import { type TransactionCategoriesWithVisibleCount, TransactionCategory } from '@/models/transaction_category.ts'; -export function setCategoryModelByAnotherCategory(category: TransactionCategory, category2: TransactionCategory): void { - category.id = category2.id; - category.type = category2.type; - category.parentId = category2.parentId; - category.name = category2.name; - category.icon = category2.icon; - category.color = category2.color; - category.comment = category2.comment; - category.visible = !category2.hidden; -} - export function transactionTypeToCategoryType(transactionType: TransactionType): CategoryType | null { if (transactionType === TransactionType.Income) { return CategoryType.Income; diff --git a/src/models/transaction_category.ts b/src/models/transaction_category.ts index f6fbb325..8123f077 100644 --- a/src/models/transaction_category.ts +++ b/src/models/transaction_category.ts @@ -1,3 +1,4 @@ +import type { ColorValue } from '@/core/color.ts'; import { type LocalizedPresetCategory, CategoryType } from '@/core/category.ts'; import { DEFAULT_CATEGORY_ICON_ID } from '@/consts/icon.ts'; import { DEFAULT_CATEGORY_COLOR } from '@/consts/color.ts'; @@ -6,15 +7,15 @@ export class TransactionCategory implements TransactionCategoryInfoResponse { public id: string; public name: string; public parentId: string; - public type: number; + public type: CategoryType; public icon: string; - public color: string; + public color: ColorValue; public comment: string; public displayOrder: number; public visible: boolean; public secondaryCategories?: TransactionCategory[]; - private constructor(id: string, name: string, parentId: string, type: number, icon: string, color: string, comment: string, displayOrder: number, visible: boolean, secondaryCategories?: TransactionCategory[]) { + private constructor(id: string, name: string, parentId: string, type: CategoryType, icon: string, color: ColorValue, comment: string, displayOrder: number, visible: boolean, secondaryCategories?: TransactionCategory[]) { this.id = id; this.name = name; this.parentId = parentId; @@ -52,6 +53,17 @@ export class TransactionCategory implements TransactionCategoryInfoResponse { return ret; } + public from(other: TransactionCategory): void { + this.id = other.id; + this.name = other.name; + this.parentId = other.parentId; + this.type = other.type; + this.icon = other.icon; + this.color = other.color; + this.comment = other.comment; + this.visible = other.visible; + } + public toCreateRequest(clientSessionId: string): TransactionCategoryCreateRequest { return { name: this.name, @@ -92,13 +104,13 @@ export class TransactionCategory implements TransactionCategoryInfoResponse { } public static ofMany(categoryResponses: TransactionCategoryInfoResponse[]): TransactionCategory[] { - const tags: TransactionCategory[] = []; + const categories: TransactionCategory[] = []; - for (const tagResponse of categoryResponses) { - tags.push(TransactionCategory.of(tagResponse)); + for (const categoryResponse of categoryResponses) { + categories.push(TransactionCategory.of(categoryResponse)); } - return tags; + return categories; } public static ofMap(categoriesByType: Record): Record { diff --git a/src/views/desktop/categories/list/dialogs/EditDialog.vue b/src/views/desktop/categories/list/dialogs/EditDialog.vue index 65f08f84..9af84eec 100644 --- a/src/views/desktop/categories/list/dialogs/EditDialog.vue +++ b/src/views/desktop/categories/list/dialogs/EditDialog.vue @@ -103,10 +103,7 @@ import { ALL_CATEGORY_COLORS } from '@/consts/color.ts'; import { TransactionCategory } from '@/models/transaction_category.ts'; import { generateRandomUUID } from '@/lib/misc.ts'; -import { - setCategoryModelByAnotherCategory, - allVisiblePrimaryTransactionCategoriesByType -} from '@/lib/category.ts'; +import { allVisiblePrimaryTransactionCategoriesByType } from '@/lib/category.ts'; export default { props: [ @@ -176,18 +173,18 @@ export default { self.submitting = false; const newTransactionCategory = TransactionCategory.createNewCategory(); - setCategoryModelByAnotherCategory(self.category, newTransactionCategory); + self.category.from(newTransactionCategory); if (options.id) { if (options.currentCategory) { - setCategoryModelByAnotherCategory(self.category, options.currentCategory); + self.category.from(options.currentCategory); } self.editCategoryId = options.id; self.transactionCategoriesStore.getCategory({ categoryId: self.editCategoryId }).then(category => { - setCategoryModelByAnotherCategory(self.category, category); + self.category.from(category); self.loading = false; }).catch(error => { self.loading = false; diff --git a/src/views/mobile/categories/EditPage.vue b/src/views/mobile/categories/EditPage.vue index fabcbc3e..3cb3bb17 100644 --- a/src/views/mobile/categories/EditPage.vue +++ b/src/views/mobile/categories/EditPage.vue @@ -156,10 +156,7 @@ import { TransactionCategory } from '@/models/transaction_category.ts'; import { getNameByKeyValue } from '@/lib/common.ts'; import { generateRandomUUID } from '@/lib/misc.ts'; -import { - setCategoryModelByAnotherCategory, - allVisiblePrimaryTransactionCategoriesByType -} from '@/lib/category.ts'; +import { allVisiblePrimaryTransactionCategoriesByType } from '@/lib/category.ts'; export default { props: [ @@ -238,7 +235,7 @@ export default { self.transactionCategoriesStore.getCategory({ categoryId: self.editCategoryId }).then(category => { - setCategoryModelByAnotherCategory(self.category, category); + self.category.from(category); self.loading = false; }).catch(error => { if (error.processed) {