migrate root store to composition API and typescript

This commit is contained in:
MaysWind
2025-01-20 00:33:22 +08:00
parent 929d3febb0
commit 559e8259be
22 changed files with 618 additions and 556 deletions
+70 -3
View File
@@ -2,10 +2,9 @@ import { LongDateFormat, ShortDateFormat, LongTimeFormat, ShortTimeFormat } from
import { DecimalSeparator, DigitGroupingSymbol, DigitGroupingType } from '@/core/numeral.ts';
import { CurrencyDisplayType } from '@/core/currency.ts';
import { PresetAmountColor } from '@/core/color.ts';
import type { LocalizedPresetCategory } from '@/core/category.ts';
import { TransactionEditScopeType } from '@/core/transaction.ts';
import type { TransactionCategoryCreateBatchRequest } from './transaction_category.ts';
export class User {
public username: string = '';
public password: string = '';
@@ -16,12 +15,80 @@ export class User {
public defaultCurrency: string;
public firstDayOfWeek: number;
public defaultAccountId?: string;
public transactionEditScope?: number;
public longDateFormat?: number;
public shortDateFormat?: number;
public longTimeFormat?: number;
public shortTimeFormat?: number;
public decimalSeparator?: number;
public digitGroupingSymbol?: number;
public digitGrouping?: number;
public currencyDisplayType?: number;
public expenseAmountColor?: number;
public incomeAmountColor?: number;
private constructor(language: string, defaultCurrency: string, firstDayOfWeek: number) {
this.language = language;
this.defaultCurrency = defaultCurrency;
this.firstDayOfWeek = firstDayOfWeek;
}
public toRegisterRequest(categories?: LocalizedPresetCategory[]): UserRegisterRequest {
return {
username: this.username,
email: this.email,
nickname: this.nickname,
password: this.password,
language: this.language,
defaultCurrency: this.defaultCurrency,
firstDayOfWeek: this.firstDayOfWeek,
categories: categories
};
}
public toProfileUpdateRequest(currentPassword?: string): UserProfileUpdateRequest {
return {
email: this.email,
nickname: this.nickname,
password: this.password,
oldPassword: currentPassword,
defaultAccountId: this.defaultAccountId,
transactionEditScope: this.transactionEditScope,
language: this.language,
defaultCurrency: this.defaultCurrency,
firstDayOfWeek: this.firstDayOfWeek,
longDateFormat: this.longDateFormat,
shortDateFormat: this.shortDateFormat,
longTimeFormat: this.longTimeFormat,
shortTimeFormat: this.shortTimeFormat,
decimalSeparator: this.decimalSeparator,
digitGroupingSymbol: this.digitGroupingSymbol,
digitGrouping: this.digitGrouping,
currencyDisplayType: this.currencyDisplayType,
expenseAmountColor: this.expenseAmountColor,
incomeAmountColor: this.incomeAmountColor
};
}
public static of(profileResponse: UserProfileResponse): User {
const user = new User(profileResponse.language, profileResponse.defaultCurrency, profileResponse.firstDayOfWeek);
user.defaultAccountId = profileResponse.defaultAccountId;
user.transactionEditScope = profileResponse.transactionEditScope;
user.longDateFormat = profileResponse.longDateFormat;
user.shortDateFormat = profileResponse.shortDateFormat;
user.longTimeFormat = profileResponse.longTimeFormat;
user.shortTimeFormat = profileResponse.shortTimeFormat;
user.decimalSeparator = profileResponse.decimalSeparator;
user.digitGroupingSymbol = profileResponse.digitGroupingSymbol;
user.digitGrouping = profileResponse.digitGrouping;
user.currencyDisplayType = profileResponse.currencyDisplayType;
user.expenseAmountColor = profileResponse.expenseAmountColor;
user.incomeAmountColor = profileResponse.incomeAmountColor;
return user;
}
public static createNewUser(language: string, defaultCurrency: string, firstDayOfWeek: number): User {
return new User(language, defaultCurrency, firstDayOfWeek);
}
@@ -64,7 +131,7 @@ export interface UserRegisterRequest {
readonly language: string;
readonly defaultCurrency: string;
readonly firstDayOfWeek: number;
readonly categories?: TransactionCategoryCreateBatchRequest;
readonly categories?: LocalizedPresetCategory[];
}
export interface UserVerifyEmailResponse {