mirror of
https://github.com/fawney19/Aether.git
synced 2026-10-06 17:37:47 +08:00
Merge pull request #846 from RWDai/review/pr-02-user-bulk-balance
feat(admin): batch adjust user wallet balances
This commit is contained in:
@@ -17,7 +17,7 @@ vi.mock('@/utils/cache', () => ({
|
||||
cachedRequest: cachedRequestMock,
|
||||
}))
|
||||
|
||||
import { usersApi } from '@/api/users'
|
||||
import { buildUserBatchBalanceAdjustmentPayload, usersApi } from '@/api/users'
|
||||
|
||||
describe('usersApi admin list query', () => {
|
||||
beforeEach(() => {
|
||||
@@ -104,3 +104,25 @@ describe('usersApi admin list query', () => {
|
||||
expect(getMock).toHaveBeenCalledWith('/api/admin/users/target-user/api-keys')
|
||||
})
|
||||
})
|
||||
|
||||
describe('user batch wallet balance payload', () => {
|
||||
it('builds an addition payload from a valid positive amount', () => {
|
||||
expect(buildUserBatchBalanceAdjustmentPayload('add', '12.5')).toEqual({
|
||||
operation: 'add',
|
||||
amount: 12.5,
|
||||
})
|
||||
})
|
||||
|
||||
it('builds a deduction payload from a valid positive amount', () => {
|
||||
expect(buildUserBatchBalanceAdjustmentPayload('deduct', 4)).toEqual({
|
||||
operation: 'deduct',
|
||||
amount: 4,
|
||||
})
|
||||
})
|
||||
|
||||
it('rejects zero, blank, and non-finite amounts', () => {
|
||||
expect(buildUserBatchBalanceAdjustmentPayload('add', '0')).toBeNull()
|
||||
expect(buildUserBatchBalanceAdjustmentPayload('deduct', '')).toBeNull()
|
||||
expect(buildUserBatchBalanceAdjustmentPayload('deduct', '1e999')).toBeNull()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -120,9 +120,28 @@ export interface UserBatchRolePayload {
|
||||
role: UserRole
|
||||
}
|
||||
|
||||
export type UserBatchAction = 'enable' | 'disable' | 'update_access_control' | 'update_role'
|
||||
export type UserBatchBalanceOperation = 'add' | 'deduct'
|
||||
|
||||
export type UserBatchActionPayload = UserBatchAccessControlPayload | UserBatchRolePayload
|
||||
export interface UserBatchBalanceAdjustmentPayload {
|
||||
operation: UserBatchBalanceOperation
|
||||
amount: number
|
||||
}
|
||||
|
||||
export function buildUserBatchBalanceAdjustmentPayload(
|
||||
operation: UserBatchBalanceOperation,
|
||||
amountInput: string | number,
|
||||
): UserBatchBalanceAdjustmentPayload | null {
|
||||
const amount = typeof amountInput === 'number' ? amountInput : Number(amountInput.trim())
|
||||
if (!Number.isFinite(amount) || amount <= 0) return null
|
||||
return { operation, amount }
|
||||
}
|
||||
|
||||
export type UserBatchAction = 'enable' | 'disable' | 'update_access_control' | 'update_role' | 'adjust_wallet_balance'
|
||||
|
||||
export type UserBatchActionPayload =
|
||||
| UserBatchAccessControlPayload
|
||||
| UserBatchRolePayload
|
||||
| UserBatchBalanceAdjustmentPayload
|
||||
|
||||
export interface UserBatchToggleActionRequest {
|
||||
selection: UserBatchSelection
|
||||
@@ -142,10 +161,18 @@ export interface UserBatchRoleActionRequest {
|
||||
payload: UserBatchRolePayload
|
||||
}
|
||||
|
||||
export interface UserBatchBalanceActionRequest {
|
||||
selection: UserBatchSelection
|
||||
action: 'adjust_wallet_balance'
|
||||
payload: UserBatchBalanceAdjustmentPayload
|
||||
idempotency_key: string
|
||||
}
|
||||
|
||||
export type UserBatchActionRequest =
|
||||
| UserBatchToggleActionRequest
|
||||
| UserBatchAccessControlActionRequest
|
||||
| UserBatchRoleActionRequest
|
||||
| UserBatchBalanceActionRequest
|
||||
|
||||
export interface UserBatchActionFailure {
|
||||
user_id: string
|
||||
@@ -157,6 +184,10 @@ export interface UserBatchActionResponse {
|
||||
success: number
|
||||
failed: number
|
||||
failures: UserBatchActionFailure[]
|
||||
interrupted?: boolean
|
||||
completed_user_ids?: string[]
|
||||
uncertain_user_ids?: string[]
|
||||
unprocessed_user_ids?: string[]
|
||||
warnings?: UserBatchSelectionWarning[]
|
||||
action?: string
|
||||
modified_fields?: string[]
|
||||
|
||||
Reference in New Issue
Block a user