games_app/backend/dist-test-faq/services/referralRegularizationService.d.ts

81 lines
2.7 KiB
TypeScript

/**
* Admin regularization of missed prediction referral commissions
* (eligible settled bets with no payout row — typically after an empty bonus pool).
*
* Rules:
* - Unit of work = (betId, beneficiaryUserId, level)
* - Idempotent via unique payout constraint / ON CONFLICT
* - Batch: refuse entirely when allowPartial=false and totalDue > pool
* - Partial: FIFO by bet.created_at ASC, then level ASC; stop at first insufficient pool
* - Never reduce a commission amount to fit the pool
*/
export declare class ReferralRegularizationError extends Error {
readonly code: 'INSUFFICIENT_POOL' | 'NOTHING_TO_DO' | 'INVALID_SELECTION' | 'LOCKED';
constructor(message: string, code?: 'INSUFFICIENT_POOL' | 'NOTHING_TO_DO' | 'INVALID_SELECTION' | 'LOCKED');
}
export type RegularizationItem = {
itemKey: string;
betId: string;
referredUserId: string;
referredDisplayName: string;
beneficiaryUserId: string;
level: number;
stakeRaw: string;
commissionPercent: number;
commissionAmountRaw: string;
betStatus: 'won' | 'lost';
betCreatedAt: string;
stakeAccountKind: string;
};
export type RegularizationBeneficiary = {
beneficiaryUserId: string;
displayName: string;
email: string | null;
pendingCount: number;
amountDueRaw: string;
oldestCreatedAt: string;
items: RegularizationItem[];
};
export type RegularizationSnapshot = {
walletTypeId: number;
poolBalanceRaw: string;
totalDueRaw: string;
shortfallRaw: string;
pendingItemCount: number;
beneficiaryCount: number;
beneficiaries: RegularizationBeneficiary[];
};
/** Build flat list of unpaid prediction commission items (eligible only). */
export declare function listPendingRegularizationItems(options?: {
search?: string;
}): Promise<{
settingsWalletTypeId: number;
items: RegularizationItem[];
}>;
export declare function getRegularizationSnapshot(options?: {
search?: string;
}): Promise<RegularizationSnapshot>;
export type RegularizeMode = 'one' | 'selected' | 'all';
export type RegularizeApplyInput = {
mode: RegularizeMode;
adminUserId: string;
beneficiaryUserIds?: string[];
allowPartial: boolean;
};
export type RegularizeApplyResult = {
paidCount: number;
paidAmountRaw: string;
reviewQueued: number;
remainingCount: number;
remainingAmountRaw: string;
skippedInsufficientPool: number;
skippedOther: number;
poolBalanceBeforeRaw: string;
poolBalanceAfterRaw: string;
shortfallRaw: string;
stoppedForInsufficientPool: boolean;
refused: boolean;
message: string;
};
export declare function applyRegularization(input: RegularizeApplyInput): Promise<RegularizeApplyResult>;
//# sourceMappingURL=referralRegularizationService.d.ts.map