migrate services.js to ts

This commit is contained in:
MaysWind
2025-01-05 17:00:25 +08:00
parent 41d34af4c7
commit 454e97c9f1
37 changed files with 1294 additions and 764 deletions
+63
View File
@@ -0,0 +1,63 @@
export interface AccountCreateRequest {
readonly name: string;
readonly category: number;
readonly type: number;
readonly icon: string;
readonly color: string;
readonly currency: string;
readonly balance: number;
readonly balanceTime: number;
readonly comment: string;
readonly creditCardStatementDate: number;
readonly subAccounts?: AccountCreateRequest[];
readonly clientSessionId: string;
}
export interface AccountModifyRequest {
readonly id: string;
readonly name: string;
readonly category: number;
readonly icon: string;
readonly color: string;
readonly comment: string;
readonly creditCardStatementDate?: number;
readonly hidden: boolean;
readonly subAccounts?: AccountModifyRequest[];
}
export interface AccountInfoResponse {
readonly id: string;
readonly name: string;
readonly parentId: string;
readonly category: number;
readonly type: number;
readonly icon: string;
readonly color: string;
readonly currency: string;
readonly balance: number;
readonly comment: string;
readonly creditCardStatementDate?: number;
readonly displayOrder: number;
readonly isAsset?: boolean;
readonly isLiability?: boolean;
readonly hidden: boolean;
readonly subAccounts?: AccountInfoResponse[];
}
export interface AccountHideRequest {
readonly id: string;
readonly hidden: boolean;
}
export interface AccountMoveRequest {
readonly newDisplayOrders: AccountNewDisplayOrderRequest[];
}
export interface AccountNewDisplayOrderRequest {
readonly id: string;
readonly displayOrder: number;
}
export interface AccountDeleteRequest {
readonly id: string;
}
+13
View File
@@ -0,0 +1,13 @@
import type { UserBasicInfo } from './user.ts';
export interface AuthResponse {
token: string;
need2FA: boolean;
user?: UserBasicInfo;
notificationContent?: string;
}
export interface RegisterResponse extends AuthResponse {
needVerifyEmail: boolean;
presetCategoriesSaved: boolean;
}
+13
View File
@@ -0,0 +1,13 @@
export interface ClearDataRequest {
readonly password: string;
}
export interface DataStatisticsResponse {
readonly totalAccountCount: number;
readonly totalTransactionCategoryCount: number;
readonly totalTransactionTagCount: number;
readonly totalTransactionCount: number;
readonly totalTransactionPictureCount: number;
readonly totalTransactionTemplateCount: number;
readonly totalScheduledTransactionCount: number;
}
+12
View File
@@ -0,0 +1,12 @@
export interface LatestExchangeRate {
readonly currency: string;
readonly rate: string;
}
export interface LatestExchangeRateResponse {
readonly dataSource: string;
readonly referenceUrl: string;
readonly updateTime: number;
readonly baseCurrency: string;
readonly exchangeRates: LatestExchangeRate[];
}
+3
View File
@@ -0,0 +1,3 @@
export interface ForgetPasswordRequest {
readonly email: string;
}
+26
View File
@@ -0,0 +1,26 @@
import type { TransactionGeoLocationResponse } from './transaction.ts';
export interface ImportTransactionResponse {
readonly type: number;
readonly categoryId: string;
readonly originalCategoryName: string;
readonly time: number;
readonly utcOffset: number;
readonly sourceAccountId: string;
readonly originalSourceAccountName: string;
readonly originalSourceAccountCurrency: string;
readonly destinationAccountId?: string;
readonly originalDestinationAccountName?: string;
readonly originalDestinationAccountCurrency?: string;
readonly sourceAmount: number;
readonly destinationAmount?: number;
readonly tagIds: string[];
readonly originalTagNames: string[];
readonly comment: string;
readonly geoLocation?: TransactionGeoLocationResponse;
}
export interface ImportTransactionResponsePageWrapper {
readonly items: ImportTransactionResponse[];
readonly totalCount: number;
}
+9
View File
@@ -1,5 +1,14 @@
import type { UserBasicInfo } from './user.ts';
export const TOKEN_CLI_USER_AGENT: string = 'ezbookkeeping Cli';
export interface TokenRefreshResponse {
readonly newToken?: string;
readonly oldTokenId?: string;
readonly user: UserBasicInfo;
readonly notificationContent?: string;
}
export interface TokenInfoResponse {
readonly tokenId: string;
readonly tokenType: number;
+267
View File
@@ -0,0 +1,267 @@
import type { StartEndTime } from '@/core/datetime.ts';
import type { AccountInfoResponse } from './account.ts';
import type { TransactionCategoryInfoResponse } from './transaction_category.ts';
import type { TransactionPictureInfoBasicResponse } from './transaction_picture_info.ts';
import type { TransactionTagInfoResponse } from './transaction_tag.ts';
export interface TransactionGeoLocationRequest {
readonly latitude: number;
readonly longitude: number;
}
export interface TransactionCreateRequest {
readonly type: number;
readonly categoryId: string;
readonly time: number;
readonly utcOffset: number;
readonly sourceAccountId: string;
readonly destinationAccountId: string;
readonly sourceAmount: number;
readonly destinationAmount: number;
readonly hideAmount: boolean;
readonly tagIds: string[];
readonly pictureIds: string[];
readonly comment: string;
readonly geoLocation?: TransactionGeoLocationRequest;
readonly clientSessionId: string;
}
export interface TransactionModifyRequest {
readonly id: string;
readonly categoryId: string;
readonly time: number;
readonly utcOffset: number;
readonly sourceAccountId: string;
readonly destinationAccountId: string;
readonly sourceAmount: number;
readonly destinationAmount: number;
readonly hideAmount: boolean;
readonly tagIds: string[];
readonly pictureIds: string[];
readonly comment: string;
readonly geoLocation?: TransactionGeoLocationRequest;
}
export interface TransactionDeleteRequest {
readonly id: string;
}
export interface TransactionImportRequest {
readonly transactions: TransactionCreateRequest[];
readonly clientSessionId: string;
}
export interface TransactionListByMaxTimeRequest {
readonly maxTime: number;
readonly minTime: number;
readonly count: number;
readonly page: number;
readonly withCount: boolean;
readonly type: number;
readonly categoryIds: string;
readonly accountIds: string;
readonly tagIds: string;
readonly tagFilterType: number;
readonly amountFilter: string;
readonly keyword: string;
}
export interface TransactionListInMonthByPageRequest {
readonly year: number;
readonly month: number;
readonly type: number;
readonly categoryIds: string;
readonly accountIds: string;
readonly tagIds: string;
readonly tagFilterType: number;
readonly amountFilter: string;
readonly keyword: string;
}
export interface TransactionGeoLocationResponse {
readonly latitude: number;
readonly longitude: number;
}
export interface TransactionInfoResponse {
readonly id: string;
readonly timeSequenceId: string;
readonly type: number;
readonly categoryId: string;
readonly category?: TransactionCategoryInfoResponse;
readonly time: number;
readonly utcOffset: number;
readonly sourceAccountId: string;
readonly sourceAccount?: AccountInfoResponse;
readonly destinationAccountId: string;
readonly destinationAccount?: AccountInfoResponse;
readonly sourceAmount: number;
readonly destinationAmount: number;
readonly hideAmount: boolean;
readonly tagIds: string[];
readonly tags?: TransactionTagInfoResponse[];
readonly pictures?: TransactionPictureInfoBasicResponse[];
readonly comment: string;
readonly geoLocation?: TransactionGeoLocationResponse;
readonly editable: boolean;
}
export interface TransactionStatisticRequest {
readonly startTime: number;
readonly endTime: number;
readonly tagIds: string;
readonly tagFilterType: number;
readonly useTransactionTimezone: boolean;
}
export interface YearMonthRangeRequest {
readonly startYearMonth: string;
readonly endYearMonth: string;
}
export interface TransactionStatisticTrendsRequest extends YearMonthRangeRequest {
readonly tagIds: string;
readonly tagFilterType: number;
readonly useTransactionTimezone: boolean;
}
export interface TransactionAmountsRequestParams {
readonly useTransactionTimezone: boolean;
readonly today: StartEndTime;
readonly thisWeek: StartEndTime;
readonly thisMonth: StartEndTime;
readonly thisYear: StartEndTime;
readonly lastMonth: StartEndTime;
readonly monthBeforeLastMonth: StartEndTime;
readonly monthBeforeLast2Months: StartEndTime;
readonly monthBeforeLast3Months: StartEndTime;
readonly monthBeforeLast4Months: StartEndTime;
readonly monthBeforeLast5Months: StartEndTime;
readonly monthBeforeLast6Months: StartEndTime;
readonly monthBeforeLast7Months: StartEndTime;
readonly monthBeforeLast8Months: StartEndTime;
readonly monthBeforeLast9Months: StartEndTime;
readonly monthBeforeLast10Months: StartEndTime;
}
export class TransactionAmountsRequest {
public readonly useTransactionTimezone: boolean;
public readonly query: string;
constructor(useTransactionTimezone: boolean, query: string) {
this.useTransactionTimezone = useTransactionTimezone;
this.query = query;
}
public buildQuery(): string {
return `use_transaction_timezone=${this.useTransactionTimezone}` + (this.query.length ? '&query=' + this.query : '');
}
public static of(params: TransactionAmountsRequestParams): TransactionAmountsRequest {
const queryParams = [];
if (params.today) {
queryParams.push(`today_${params.today.startTime}_${params.today.endTime}`);
}
if (params.thisWeek) {
queryParams.push(`thisWeek_${params.thisWeek.startTime}_${params.thisWeek.endTime}`);
}
if (params.thisMonth) {
queryParams.push(`thisMonth_${params.thisMonth.startTime}_${params.thisMonth.endTime}`);
}
if (params.thisYear) {
queryParams.push(`thisYear_${params.thisYear.startTime}_${params.thisYear.endTime}`);
}
if (params.lastMonth) {
queryParams.push(`lastMonth_${params.lastMonth.startTime}_${params.lastMonth.endTime}`);
}
if (params.monthBeforeLastMonth) {
queryParams.push(`monthBeforeLastMonth_${params.monthBeforeLastMonth.startTime}_${params.monthBeforeLastMonth.endTime}`);
}
if (params.monthBeforeLast2Months) {
queryParams.push(`monthBeforeLast2Months_${params.monthBeforeLast2Months.startTime}_${params.monthBeforeLast2Months.endTime}`);
}
if (params.monthBeforeLast3Months) {
queryParams.push(`monthBeforeLast3Months_${params.monthBeforeLast3Months.startTime}_${params.monthBeforeLast3Months.endTime}`);
}
if (params.monthBeforeLast4Months) {
queryParams.push(`monthBeforeLast4Months_${params.monthBeforeLast4Months.startTime}_${params.monthBeforeLast4Months.endTime}`);
}
if (params.monthBeforeLast5Months) {
queryParams.push(`monthBeforeLast5Months_${params.monthBeforeLast5Months.startTime}_${params.monthBeforeLast5Months.endTime}`);
}
if (params.monthBeforeLast6Months) {
queryParams.push(`monthBeforeLast6Months_${params.monthBeforeLast6Months.startTime}_${params.monthBeforeLast6Months.endTime}`);
}
if (params.monthBeforeLast7Months) {
queryParams.push(`monthBeforeLast7Months_${params.monthBeforeLast7Months.startTime}_${params.monthBeforeLast7Months.endTime}`);
}
if (params.monthBeforeLast8Months) {
queryParams.push(`monthBeforeLast8Months_${params.monthBeforeLast8Months.startTime}_${params.monthBeforeLast8Months.endTime}`);
}
if (params.monthBeforeLast9Months) {
queryParams.push(`monthBeforeLast9Months_${params.monthBeforeLast9Months.startTime}_${params.monthBeforeLast9Months.endTime}`);
}
if (params.monthBeforeLast10Months) {
queryParams.push(`monthBeforeLast10Months_${params.monthBeforeLast10Months.startTime}_${params.monthBeforeLast10Months.endTime}`);
}
return new TransactionAmountsRequest(params.useTransactionTimezone, (queryParams.length ? queryParams.join('|') : ''));
}
}
export interface TransactionInfoPageWrapperResponse {
readonly items: TransactionInfoResponse[];
readonly nextTimeSequenceId?: string;
readonly totalCount?: number;
}
export interface TransactionInfoPageWrapperResponse2 {
readonly items: TransactionInfoResponse[];
readonly totalCount: number;
}
export interface TransactionStatisticResponse {
readonly startTime: number;
readonly endTime: number;
readonly items: TransactionStatisticResponseItem[];
}
export interface TransactionStatisticResponseItem {
readonly categoryId: string;
readonly accountId: string;
readonly totalAmount: number;
}
export interface TransactionStatisticTrendsItem {
readonly year: number;
readonly month: number;
readonly items: TransactionStatisticResponseItem[];
}
export interface TransactionAmountsResponseItem {
readonly startTime: number;
readonly endTime: number;
readonly amounts: TransactionAmountsResponseItemAmountInfo[];
}
export interface TransactionAmountsResponseItemAmountInfo {
readonly currency: string;
readonly incomeAmount: number;
readonly expenseAmount: number;
}
+63
View File
@@ -0,0 +1,63 @@
export interface TransactionCategoryCreateRequest {
readonly name: string;
readonly type: number;
readonly parentId: string;
readonly icon: string;
readonly color: string;
readonly comment: string;
readonly clientSessionId: string;
}
export interface TransactionCategoryCreateBatchRequest {
readonly categories: TransactionCategoryCreateWithSubCategories[];
}
export interface TransactionCategoryCreateWithSubCategories {
readonly name: string;
readonly type: number;
readonly icon: string;
readonly color: string;
readonly comment: string;
readonly subCategories: TransactionCategoryCreateRequest[];
}
export interface TransactionCategoryModifyRequest {
readonly id: string;
readonly name: string;
readonly parentId: string;
readonly icon: string;
readonly color: string;
readonly comment: string;
readonly hidden: boolean;
}
export interface TransactionCategoryHideRequest {
readonly id: string;
readonly hidden: boolean;
}
export interface TransactionCategoryMoveRequest {
readonly newDisplayOrders: TransactionCategoryNewDisplayOrderRequest[];
}
export interface TransactionCategoryNewDisplayOrderRequest {
readonly id: string;
readonly displayOrder: number;
}
export interface TransactionCategoryDeleteRequest {
readonly id: string;
}
export interface TransactionCategoryInfoResponse {
readonly id: string;
readonly name: string;
readonly parentId: string;
readonly type: number;
readonly icon: string;
readonly color: string;
readonly comment: string;
readonly displayOrder: number;
readonly hidden: boolean;
readonly subCategories?: TransactionCategoryInfoResponse[];
}
+8
View File
@@ -0,0 +1,8 @@
export interface TransactionPictureUnusedDeleteRequest {
readonly id: string;
}
export interface TransactionPictureInfoBasicResponse {
readonly pictureId: string;
readonly originalUrl: string;
}
+33
View File
@@ -0,0 +1,33 @@
export interface TransactionTagCreateRequest {
readonly name: string;
}
export interface TransactionTagModifyRequest {
readonly id: string;
readonly name: string;
}
export interface TransactionTagHideRequest {
readonly id: string;
readonly hidden: boolean;
}
export interface TransactionTagMoveRequest {
readonly newDisplayOrders: TransactionTagNewDisplayOrderRequest[];
}
export interface TransactionTagNewDisplayOrderRequest {
readonly id: string;
readonly displayOrder: number;
}
export interface TransactionTagDeleteRequest {
readonly id: string;
}
export interface TransactionTagInfoResponse {
readonly id: string;
readonly name: string;
readonly displayOrder: number;
readonly hidden: boolean;
}
+64
View File
@@ -0,0 +1,64 @@
import type { TransactionInfoResponse } from './transaction.ts';
export interface TransactionTemplateCreateRequest {
readonly templateType: number;
readonly name: string;
readonly type: number;
readonly categoryId: string;
readonly sourceAccountId: string;
readonly destinationAccountId: string;
readonly sourceAmount: number;
readonly destinationAmount: number;
readonly hideAmount: boolean;
readonly tagIds: string[];
readonly comment: string;
readonly scheduledFrequencyType?: number;
readonly scheduledFrequency?: string;
readonly utcOffset?: number;
readonly clientSessionId: string;
}
export interface TransactionTemplateModifyRequest {
readonly id: string;
readonly name: string;
readonly type: number;
readonly categoryId: string;
readonly sourceAccountId: string;
readonly destinationAccountId: string;
readonly sourceAmount: number;
readonly destinationAmount: number;
readonly hideAmount: boolean;
readonly tagIds: string[];
readonly comment: string;
readonly scheduledFrequencyType?: number;
readonly scheduledFrequency?: string;
readonly utcOffset?: number;
}
export interface TransactionTemplateHideRequest {
readonly id: string;
readonly hidden: boolean;
}
export interface TransactionTemplateMoveRequest {
readonly newDisplayOrders: TransactionTemplateNewDisplayOrderRequest[];
}
export interface TransactionTemplateNewDisplayOrderRequest {
readonly id: string;
readonly displayOrder: number;
}
export interface TransactionTemplateDeleteRequest {
readonly id: string;
}
export interface TransactionTemplateInfoResponse extends TransactionInfoResponse {
readonly templateType: number;
readonly name: string;
readonly scheduledFrequencyType?: number;
readonly scheduledFrequency?: string;
readonly scheduledAt?: number;
readonly displayOrder: number;
readonly hidden: boolean;
}
+27
View File
@@ -0,0 +1,27 @@
export interface TwoFactorEnableConfirmRequest {
readonly secret: string;
readonly passcode: string;
}
export interface TwoFactorEnableResponse {
readonly secret: string;
readonly qrcode: string;
}
export interface TwoFactorEnableConfirmResponse {
readonly token?: string;
readonly recoveryCodes: string[];
}
export interface TwoFactorDisableRequest {
readonly password?: string;
}
export interface TwoFactorRegenerateRecoveryCodeRequest {
readonly password?: string;
}
export interface TwoFactorStatusResponse {
readonly enable: boolean;
readonly createdAt?: number;
}
+60
View File
@@ -1,3 +1,5 @@
import type { TransactionCategoryCreateBatchRequest } from './transaction_category.ts';
export interface UserBasicInfo {
readonly username: string;
readonly email: string;
@@ -21,3 +23,61 @@ export interface UserBasicInfo {
readonly incomeAmountColor: number;
readonly emailVerified: boolean;
}
export interface UserLoginRequest {
readonly loginName: string;
readonly password: string;
}
export interface UserRegisterRequest {
readonly username: string;
readonly email: string;
readonly nickname: string;
readonly password: string;
readonly language: string;
readonly defaultCurrency: string;
readonly firstDayOfWeek: number;
readonly categories?: TransactionCategoryCreateBatchRequest;
}
export interface UserVerifyEmailResponse {
readonly newToken?: string;
readonly user: UserBasicInfo;
readonly notificationContent?: string;
}
export interface UserResendVerifyEmailRequest {
readonly email: string;
readonly password: string;
}
export interface UserProfileUpdateRequest {
readonly email?: string;
readonly nickname?: string;
readonly password?: string;
readonly oldPassword?: string;
readonly defaultAccountId?: string;
readonly transactionEditScope?: number;
readonly language?: string;
readonly defaultCurrency?: string;
readonly firstDayOfWeek?: number;
readonly longDateFormat?: number;
readonly shortDateFormat?: number;
readonly longTimeFormat?: number;
readonly shortTimeFormat?: number;
readonly decimalSeparator?: number;
readonly digitGroupingSymbol?: number;
readonly digitGrouping?: number;
readonly currencyDisplayType?: number;
readonly expenseAmountColor?: number;
readonly incomeAmountColor?: number;
}
export interface UserProfileUpdateResponse {
readonly user: UserBasicInfo;
readonly newToken?: string;
}
export interface UserProfileResponse extends UserBasicInfo {
readonly lastLoginAt: number;
}