games_app/backend/dist/services/adminService.d.ts
2026-06-29 15:01:23 +02:00

151 lines
4.8 KiB
TypeScript

/**
* Admin user management service.
* Orchestrates user repository access, email decryption, and wallet balances for admin APIs.
*/
import { RoleName } from '../models';
import type { AdminSortBy, UserActivityFilter } from '../repositories/userRepository';
/** Query options for the admin user list. */
export type AdminListUsersOptions = {
search?: string;
roleName?: RoleName;
emailVerified?: boolean;
country?: string;
inactiveSinceDays?: number;
activityFilter?: UserActivityFilter;
activityPeriodFrom?: string;
activityPeriodTo?: string;
minMainBalance?: string;
maxMainBalance?: string;
minBonusReceived?: string;
maxBonusReceived?: string;
accountStatus?: 'active' | 'disabled' | 'suspended';
hasReceivedBonus?: boolean;
createdFrom?: string;
createdTo?: string;
minAge?: number;
maxAge?: number;
totpEnabled?: boolean;
underSurveillance?: boolean;
sortBy?: AdminSortBy;
sortDir?: 'asc' | 'desc';
limit: number;
offset?: number;
cursor?: string;
includeTotal?: boolean;
userIds?: string[];
};
/** API-facing user row with decrypted email (admin list). */
export type AdminUserListItem = {
id: string;
email: string | null;
first_name: string | null;
middle_name: string | null;
last_name: string | null;
date_of_birth: string | null;
role_id: number;
role_name: string;
email_verified: boolean;
totp_enabled: boolean;
is_enabled: boolean;
is_account_non_expired: boolean;
is_account_non_locked: boolean;
is_credentials_non_expired: boolean;
country_of_residence: string | null;
nationality: string | null;
referral_code: string | null;
first_deposit_at: Date | null;
first_deposit_transaction_id: string | null;
withdrawals_suspended: boolean;
under_surveillance: boolean;
security_suspended_at: Date | null;
created_at: Date;
updated_at: Date;
main_balance_raw: string;
bonus_balance_raw: string;
total_bonus_received_raw: string;
prediction_count: number;
total_stake_raw: string;
total_payout_raw: string;
net_pnl_raw: string;
last_login_at: Date | null;
last_activity_at: Date;
account_status: 'active' | 'disabled' | 'suspended';
};
/** Account flags accepted from the admin API (camelCase). */
export type AdminAccountFlagsInput = {
isEnabled?: boolean;
isAccountNonExpired?: boolean;
isAccountNonLocked?: boolean;
isCredentialsNonExpired?: boolean;
};
export type BatchOperationResult = {
succeeded: string[];
failed: Array<{
userId: string;
error: string;
}>;
};
/**
* Lists users for the admin panel with decrypted emails and aggregated stats.
*/
export declare function listUsers(options: AdminListUsersOptions): Promise<{
users: AdminUserListItem[];
total: number | null;
totalIsExact: boolean;
nextCursor: string | null;
hasMore: boolean;
}>;
export declare function updateUserAccountFlags(userId: string, flags: AdminAccountFlagsInput): Promise<void>;
export declare function batchUpdateUserAccountFlags(userIds: string[], flags: AdminAccountFlagsInput): Promise<BatchOperationResult>;
export declare function batchUpdateUserSecurity(userIds: string[], body: {
withdrawalsSuspended?: boolean;
underSurveillance?: boolean;
reactivateWithdrawals?: boolean;
reason?: string;
}): Promise<BatchOperationResult>;
export declare function batchGrantLedgerCredit(userIds: string[], input: {
walletTypeId: number;
adjustmentType: 'bonus' | 'admin_adjustment';
amountRaw: string;
reason: string;
}, approvedBy: string): Promise<BatchOperationResult>;
/**
* Marks a user's email as verified (admin support action).
*/
export declare function markUserEmailVerified(userId: string, adminUserId: string): Promise<{
message: string;
emailVerified: boolean;
}>;
/**
* Loads full admin user details including wallet balances.
*/
export declare function getUserDetails(userId: string): Promise<{
user: {
id: string;
email: string | null;
role_id: number;
role_name: string;
email_verified: boolean;
totp_enabled: boolean;
is_enabled: boolean;
is_account_non_expired: boolean;
is_account_non_locked: boolean;
is_credentials_non_expired: boolean;
withdrawals_suspended: boolean;
under_surveillance: boolean;
security_suspended_at: Date | null;
created_at: Date;
};
balances: Array<{
wallet_type: string;
wallet_name: string;
available: string;
locked: string;
}>;
}>;
export type UserRoleName = 'user' | 'moderator' | 'admin';
export declare function updateUserRole(targetUserId: string, role: UserRoleName, adminUserId: string): Promise<{
userId: string;
role: UserRoleName;
}>;
//# sourceMappingURL=adminService.d.ts.map